pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
First day of month, last day of month
21+ messages / 9 participants
[nested] [flat]

* First day of month, last day of month
@ 2008-04-24 12:59 Nacef LABIDI <nacef.l@gmail.com>
  2008-04-24 13:06 ` Re: First day of month, last day of month Frank Bax <fbax@sympatico.ca>
  2008-04-24 13:15 ` Re: First day of month, last day of month A. Kretschmer <andreas.kretschmer@schollglas.com>
  0 siblings, 2 replies; 21+ messages in thread

From: Nacef LABIDI @ 2008-04-24 12:59 UTC (permalink / raw)
  To: pgsql-sql

Hi all,

I want to select data from a table according to a date column in my table. I
want to select all the rows which have date in the current month. So is
there a way to get from the actual date the first day and the last day of
the month or is there a better method to retrieve all the rows with dates in
the current month.

Thanks to all

^ permalink  raw  reply  [nested|flat] 21+ messages in thread

* Re: First day of month, last day of month
  2008-04-24 12:59 First day of month, last day of month Nacef LABIDI <nacef.l@gmail.com>
@ 2008-04-24 13:06 ` Frank Bax <fbax@sympatico.ca>
  2008-04-24 13:11   ` Re: First day of month, last day of month Bart Degryse <Bart.Degryse@indicator.be>
  2008-04-24 13:16   ` Re: First day of month, last day of month Frank Bax <fbax@sympatico.ca>
  1 sibling, 2 replies; 21+ messages in thread

From: Frank Bax @ 2008-04-24 13:06 UTC (permalink / raw)
  To: pgsql-sql

Nacef LABIDI wrote:
> is there a better method to retrieve all 
> the rows with dates in the current month.


select * from mytable where extract(month from mydate) = extract(month 
from now()) and extract(year from mydate) = extract(year from now());



^ permalink  raw  reply  [nested|flat] 21+ messages in thread

* Re: First day of month, last day of month
  2008-04-24 12:59 First day of month, last day of month Nacef LABIDI <nacef.l@gmail.com>
  2008-04-24 13:06 ` Re: First day of month, last day of month Frank Bax <fbax@sympatico.ca>
@ 2008-04-24 13:11   ` Bart Degryse <Bart.Degryse@indicator.be>
  1 sibling, 0 replies; 21+ messages in thread

From: Bart Degryse @ 2008-04-24 13:11 UTC (permalink / raw)
  To: pgsql-sql; Frank Bax <fbax@sympatico.ca>

select * from mytable where date_trunc('month', mydate) = date_trunc('month', now());


>>> Frank Bax <fbax@sympatico.ca> 2008-04-24 15:06 >>>
Nacef LABIDI wrote:
> is there a better method to retrieve all 
> the rows with dates in the current month.


select * from mytable where extract(month from mydate) = extract(month 
from now()) and extract(year from mydate) = extract(year from now());

-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql

^ permalink  raw  reply  [nested|flat] 21+ messages in thread

* Re: First day of month, last day of month
  2008-04-24 12:59 First day of month, last day of month Nacef LABIDI <nacef.l@gmail.com>
  2008-04-24 13:06 ` Re: First day of month, last day of month Frank Bax <fbax@sympatico.ca>
@ 2008-04-24 13:16   ` Frank Bax <fbax@sympatico.ca>
  2008-04-24 14:15     ` Re: First day of month, last day of month Colin Wetherbee <cww@denterprises.org>
  1 sibling, 1 reply; 21+ messages in thread

From: Frank Bax @ 2008-04-24 13:16 UTC (permalink / raw)
  To: pgsql-sql

Frank Bax wrote:
> Nacef LABIDI wrote:
>> is there a better method to retrieve all the rows with dates in the 
>> current month.
> 
> 
> select * from mytable where extract(month from mydate) = extract(month 
> from now()) and extract(year from mydate) = extract(year from now());


Sorry; I was not thinking clearly - date_trunc is better for this:

select * from mytable where date_trunc('month',mydate) = 
date_trunc('month',now());



^ permalink  raw  reply  [nested|flat] 21+ messages in thread

* Re: First day of month, last day of month
  2008-04-24 12:59 First day of month, last day of month Nacef LABIDI <nacef.l@gmail.com>
  2008-04-24 13:06 ` Re: First day of month, last day of month Frank Bax <fbax@sympatico.ca>
  2008-04-24 13:16   ` Re: First day of month, last day of month Frank Bax <fbax@sympatico.ca>
@ 2008-04-24 14:15     ` Colin Wetherbee <cww@denterprises.org>
  2008-04-24 14:41       ` Re: First day of month, last day of month Erik Jones <erik@myemma.com>
  2008-04-24 14:42       ` Re: First day of month, last day of month Bart Degryse <Bart.Degryse@indicator.be>
  2008-04-24 14:43       ` Re: First day of month, last day of month Nacef LABIDI <nacef.l@gmail.com>
  2008-04-24 14:47       ` Re: First day of month, last day of month Bart Degryse <Bart.Degryse@indicator.be>
  0 siblings, 4 replies; 21+ messages in thread

From: Colin Wetherbee @ 2008-04-24 14:15 UTC (permalink / raw)
  To: Frank Bax <fbax@sympatico.ca>; +Cc: pgsql-sql

Frank Bax wrote:
> Frank Bax wrote:
>> Nacef LABIDI wrote:
>>> is there a better method to retrieve all the rows with dates in the 
>>> current month.
>>
>> select * from mytable where extract(month from mydate) = extract(month 
>> from now()) and extract(year from mydate) = extract(year from now());
> 
> Sorry; I was not thinking clearly - date_trunc is better for this:
> 
> select * from mytable where date_trunc('month',mydate) = 
> date_trunc('month',now());

I have some code that uses extract() for this sort of thing.  Would you 
mind explaining how date_trunc() is better for this?

Most of my extract() results end up in <select> drop-down boxes in HTML.

Thanks.

Colin




^ permalink  raw  reply  [nested|flat] 21+ messages in thread

* Re: First day of month, last day of month
  2008-04-24 12:59 First day of month, last day of month Nacef LABIDI <nacef.l@gmail.com>
  2008-04-24 13:06 ` Re: First day of month, last day of month Frank Bax <fbax@sympatico.ca>
  2008-04-24 13:16   ` Re: First day of month, last day of month Frank Bax <fbax@sympatico.ca>
  2008-04-24 14:15     ` Re: First day of month, last day of month Colin Wetherbee <cww@denterprises.org>
@ 2008-04-24 14:41       ` Erik Jones <erik@myemma.com>
  3 siblings, 0 replies; 21+ messages in thread

From: Erik Jones @ 2008-04-24 14:41 UTC (permalink / raw)
  To: Colin Wetherbee <cww@denterprises.org>; +Cc: Frank Bax <fbax@sympatico.ca>; pgsql-sql


On Apr 24, 2008, at 9:15 AM, Colin Wetherbee wrote:

> Frank Bax wrote:
>> Frank Bax wrote:
>>> Nacef LABIDI wrote:
>>>> is there a better method to retrieve all the rows with dates in  
>>>> the current month.
>>>
>>> select * from mytable where extract(month from mydate) =  
>>> extract(month from now()) and extract(year from mydate) =  
>>> extract(year from now());
>> Sorry; I was not thinking clearly - date_trunc is better for this:
>> select * from mytable where date_trunc('month',mydate) =  
>> date_trunc('month',now());
>
> I have some code that uses extract() for this sort of thing.  Would  
> you mind explaining how date_trunc() is better for this?
>
> Most of my extract() results end up in <select> drop-down boxes in  
> HTML.


extract will pull specific date unit value out of a given date/ 
timestamp/interval.  date_trunc will "round" a given date/timestamp  
down to the given unit.

extract(month from now()) -> 4

date_trunc('month', now()) -> 2008-04-01 00:00:00-05

I typically find date_trunc much more useful but I may just think that  
because I've been writing partitioning code a lot lately.

Erik Jones

DBA | Emma®
erik@myemma.com
800.595.4401 or 615.292.5888
615.292.0777 (fax)

Emma helps organizations everywhere communicate & market in style.
Visit us online at http://www.myemma.com






^ permalink  raw  reply  [nested|flat] 21+ messages in thread

* Re: First day of month, last day of month
  2008-04-24 12:59 First day of month, last day of month Nacef LABIDI <nacef.l@gmail.com>
  2008-04-24 13:06 ` Re: First day of month, last day of month Frank Bax <fbax@sympatico.ca>
  2008-04-24 13:16   ` Re: First day of month, last day of month Frank Bax <fbax@sympatico.ca>
  2008-04-24 14:15     ` Re: First day of month, last day of month Colin Wetherbee <cww@denterprises.org>
@ 2008-04-24 14:42       ` Bart Degryse <Bart.Degryse@indicator.be>
  3 siblings, 0 replies; 21+ messages in thread

From: Bart Degryse @ 2008-04-24 14:42 UTC (permalink / raw)
  To: Colin Wetherbee <cww@denterprises.org>; Frank Bax <fbax@sympatico.ca>; +Cc: pgsql-sql

Don't know whether it's better, but it's shorter.
With extract you have to make the extraction for both year and month (unless cases where either one doesn't matter)
With date_trunc('month', ...) you throw away anything smaller than month in one step.
I suppose having to call the function date_trunc twice and extract 4 times in the given example could make
the date_trunc version slightly faster.
Just wondering how many times you would have to do it before noticing the "speedup".


>>> Colin Wetherbee <cww@denterprises.org> 2008-04-24 16:15 >>>
Frank Bax wrote:
> Frank Bax wrote:
>> Nacef LABIDI wrote:
>>> is there a better method to retrieve all the rows with dates in the 
>>> current month.
>>
>> select * from mytable where extract(month from mydate) = extract(month 
>> from now()) and extract(year from mydate) = extract(year from now());
> 
> Sorry; I was not thinking clearly - date_trunc is better for this:
> 
> select * from mytable where date_trunc('month',mydate) = 
> date_trunc('month',now());

I have some code that uses extract() for this sort of thing.  Would you 
mind explaining how date_trunc() is better for this?

Most of my extract() results end up in <select> drop-down boxes in HTML.

Thanks.

Colin


-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql

^ permalink  raw  reply  [nested|flat] 21+ messages in thread

* Re: First day of month, last day of month
  2008-04-24 12:59 First day of month, last day of month Nacef LABIDI <nacef.l@gmail.com>
  2008-04-24 13:06 ` Re: First day of month, last day of month Frank Bax <fbax@sympatico.ca>
  2008-04-24 13:16   ` Re: First day of month, last day of month Frank Bax <fbax@sympatico.ca>
  2008-04-24 14:15     ` Re: First day of month, last day of month Colin Wetherbee <cww@denterprises.org>
@ 2008-04-24 14:43       ` Nacef LABIDI <nacef.l@gmail.com>
  2008-04-24 14:55         ` Re: First day of month, last day of month Scott Marlowe <scott.marlowe@gmail.com>
  3 siblings, 1 reply; 21+ messages in thread

From: Nacef LABIDI @ 2008-04-24 14:43 UTC (permalink / raw)
  To: Colin Wetherbee <cww@denterprises.org>; +Cc: Frank Bax <fbax@sympatico.ca>; pgsql-sql

Actually I want to select all rows whith dates between first day of the
month 00:00:00 and last date of the month 23:59:59

On Thu, Apr 24, 2008 at 4:15 PM, Colin Wetherbee <cww@denterprises.org>
wrote:

> Frank Bax wrote:
>
> > Frank Bax wrote:
> >
> > > Nacef LABIDI wrote:
> > >
> > > > is there a better method to retrieve all the rows with dates in the
> > > > current month.
> > > >
> > >
> > > select * from mytable where extract(month from mydate) = extract(month
> > > from now()) and extract(year from mydate) = extract(year from now());
> > >
> >
> > Sorry; I was not thinking clearly - date_trunc is better for this:
> >
> > select * from mytable where date_trunc('month',mydate) =
> > date_trunc('month',now());
> >
>
> I have some code that uses extract() for this sort of thing.  Would you
> mind explaining how date_trunc() is better for this?
>
> Most of my extract() results end up in <select> drop-down boxes in HTML.
>
> Thanks.
>
> Colin
>
>
> --
> Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-sql
>

^ permalink  raw  reply  [nested|flat] 21+ messages in thread

* Re: First day of month, last day of month
  2008-04-24 12:59 First day of month, last day of month Nacef LABIDI <nacef.l@gmail.com>
  2008-04-24 13:06 ` Re: First day of month, last day of month Frank Bax <fbax@sympatico.ca>
  2008-04-24 13:16   ` Re: First day of month, last day of month Frank Bax <fbax@sympatico.ca>
  2008-04-24 14:15     ` Re: First day of month, last day of month Colin Wetherbee <cww@denterprises.org>
  2008-04-24 14:43       ` Re: First day of month, last day of month Nacef LABIDI <nacef.l@gmail.com>
@ 2008-04-24 14:55         ` Scott Marlowe <scott.marlowe@gmail.com>
  2008-04-24 15:10           ` Re: First day of month, last day of month Fernando Hevia <fhevia@ip-tel.com.ar>
  0 siblings, 1 reply; 21+ messages in thread

From: Scott Marlowe @ 2008-04-24 14:55 UTC (permalink / raw)
  To: Nacef LABIDI <nacef.l@gmail.com>; +Cc: Colin Wetherbee <cww@denterprises.org>; Frank Bax <fbax@sympatico.ca>; pgsql-sql

On Thu, Apr 24, 2008 at 8:43 AM, Nacef LABIDI <nacef.l@gmail.com> wrote:
> Actually I want to select all rows whith dates between first day of the
> month 00:00:00 and last date of the month 23:59:59

Then you can just use date_trunc on the values in the database. Plus
if you're using timestamp WITHOUT timezone, you can index on it.

create index table_datefield_month_trunc on table
(date_trunc('month',datefield));
select * from table where
date_trunc('month',timestampfield)='2007-10-01 00:00:00';



^ permalink  raw  reply  [nested|flat] 21+ messages in thread

* Re: First day of month, last day of month
  2008-04-24 12:59 First day of month, last day of month Nacef LABIDI <nacef.l@gmail.com>
  2008-04-24 13:06 ` Re: First day of month, last day of month Frank Bax <fbax@sympatico.ca>
  2008-04-24 13:16   ` Re: First day of month, last day of month Frank Bax <fbax@sympatico.ca>
  2008-04-24 14:15     ` Re: First day of month, last day of month Colin Wetherbee <cww@denterprises.org>
  2008-04-24 14:43       ` Re: First day of month, last day of month Nacef LABIDI <nacef.l@gmail.com>
  2008-04-24 14:55         ` Re: First day of month, last day of month Scott Marlowe <scott.marlowe@gmail.com>
@ 2008-04-24 15:10           ` Fernando Hevia <fhevia@ip-tel.com.ar>
  2008-04-24 15:16             ` Re: First day of month, last day of month Scott Marlowe <scott.marlowe@gmail.com>
  0 siblings, 1 reply; 21+ messages in thread

From: Fernando Hevia @ 2008-04-24 15:10 UTC (permalink / raw)
  To: pgsql-sql

 

> -----Mensaje original-----
> De: pgsql-sql-owner@postgresql.org 
> [mailto:pgsql-sql-owner@postgresql.org] En nombre de Scott Marlowe
> 
> Then you can just use date_trunc on the values in the 
> database. Plus if you're using timestamp WITHOUT timezone, 
> you can index on it.
> 

Did not understand this. Are you saying timestamps WITH timezone are NOT
indexable or you mean that you cant build a partial index on a
timestamp-with-time-zone returning function?

Regards,
Fernando.




^ permalink  raw  reply  [nested|flat] 21+ messages in thread

* Re: First day of month, last day of month
  2008-04-24 12:59 First day of month, last day of month Nacef LABIDI <nacef.l@gmail.com>
  2008-04-24 13:06 ` Re: First day of month, last day of month Frank Bax <fbax@sympatico.ca>
  2008-04-24 13:16   ` Re: First day of month, last day of month Frank Bax <fbax@sympatico.ca>
  2008-04-24 14:15     ` Re: First day of month, last day of month Colin Wetherbee <cww@denterprises.org>
  2008-04-24 14:43       ` Re: First day of month, last day of month Nacef LABIDI <nacef.l@gmail.com>
  2008-04-24 14:55         ` Re: First day of month, last day of month Scott Marlowe <scott.marlowe@gmail.com>
  2008-04-24 15:10           ` Re: First day of month, last day of month Fernando Hevia <fhevia@ip-tel.com.ar>
@ 2008-04-24 15:16             ` Scott Marlowe <scott.marlowe@gmail.com>
  2008-04-24 15:44               ` Re: First day of month, last day of month Scott Marlowe <scott.marlowe@gmail.com>
  0 siblings, 1 reply; 21+ messages in thread

From: Scott Marlowe @ 2008-04-24 15:16 UTC (permalink / raw)
  To: Fernando Hevia <fhevia@ip-tel.com.ar>; +Cc: pgsql-sql

On Thu, Apr 24, 2008 at 9:10 AM, Fernando Hevia <fhevia@ip-tel.com.ar> wrote:
>  > De: pgsql-sql-owner@postgresql.org
>  > [mailto:pgsql-sql-owner@postgresql.org] En nombre de Scott Marlowe
>
> >
>  > Then you can just use date_trunc on the values in the
>  > database. Plus if you're using timestamp WITHOUT timezone,
>  > you can index on it.
>  >
>
>  Did not understand this. Are you saying timestamps WITH timezone are NOT
>  indexable or you mean that you cant build a partial index on a
>  timestamp-with-time-zone returning function?

Correct, timestamptz or timestamp with timezone (timestamptz is the
shorter alias) are not indexable because functions in an index must be
immutable, and date_trunc on a timestamptz is not.



^ permalink  raw  reply  [nested|flat] 21+ messages in thread

* Re: First day of month, last day of month
  2008-04-24 12:59 First day of month, last day of month Nacef LABIDI <nacef.l@gmail.com>
  2008-04-24 13:06 ` Re: First day of month, last day of month Frank Bax <fbax@sympatico.ca>
  2008-04-24 13:16   ` Re: First day of month, last day of month Frank Bax <fbax@sympatico.ca>
  2008-04-24 14:15     ` Re: First day of month, last day of month Colin Wetherbee <cww@denterprises.org>
  2008-04-24 14:43       ` Re: First day of month, last day of month Nacef LABIDI <nacef.l@gmail.com>
  2008-04-24 14:55         ` Re: First day of month, last day of month Scott Marlowe <scott.marlowe@gmail.com>
  2008-04-24 15:10           ` Re: First day of month, last day of month Fernando Hevia <fhevia@ip-tel.com.ar>
  2008-04-24 15:16             ` Re: First day of month, last day of month Scott Marlowe <scott.marlowe@gmail.com>
@ 2008-04-24 15:44               ` Scott Marlowe <scott.marlowe@gmail.com>
  2008-04-24 16:07                 ` Re: First day of month, last day of month Fernando Hevia <fhevia@ip-tel.com.ar>
  0 siblings, 1 reply; 21+ messages in thread

From: Scott Marlowe @ 2008-04-24 15:44 UTC (permalink / raw)
  To: Fernando Hevia <fhevia@ip-tel.com.ar>; +Cc: pgsql-sql

On Thu, Apr 24, 2008 at 9:16 AM, Scott Marlowe <scott.marlowe@gmail.com> wrote:
> On Thu, Apr 24, 2008 at 9:10 AM, Fernando Hevia <fhevia@ip-tel.com.ar> wrote:
>  >  > De: pgsql-sql-owner@postgresql.org
>  >  > [mailto:pgsql-sql-owner@postgresql.org] En nombre de Scott Marlowe
>  >
>  > >
>  >  > Then you can just use date_trunc on the values in the
>  >  > database. Plus if you're using timestamp WITHOUT timezone,
>  >  > you can index on it.
>  >  >
>  >
>  >  Did not understand this. Are you saying timestamps WITH timezone are NOT
>  >  indexable or you mean that you cant build a partial index on a
>  >  timestamp-with-time-zone returning function?
>
>  Correct, timestamptz or timestamp with timezone (timestamptz is the
>  shorter alias) are not indexable because functions in an index must be
>  immutable, and date_trunc on a timestamptz is not.

Note that if you are storing your time stamp as timestamptz, you can
use the "at time zone 'xyz'" construct to create an index, and as long
as you retrieve them with the same construct you'll get to use the
index.

create index test_ts_month_trunc on testtable (date_trunc('month',(ts
at time zone 'MST')));
select * from testtable where date_trunc('month',(ts at time zone
'MST'))='2007-10-01 00:00:00'::timestamp;



^ permalink  raw  reply  [nested|flat] 21+ messages in thread

* Re: First day of month, last day of month
  2008-04-24 12:59 First day of month, last day of month Nacef LABIDI <nacef.l@gmail.com>
  2008-04-24 13:06 ` Re: First day of month, last day of month Frank Bax <fbax@sympatico.ca>
  2008-04-24 13:16   ` Re: First day of month, last day of month Frank Bax <fbax@sympatico.ca>
  2008-04-24 14:15     ` Re: First day of month, last day of month Colin Wetherbee <cww@denterprises.org>
  2008-04-24 14:43       ` Re: First day of month, last day of month Nacef LABIDI <nacef.l@gmail.com>
  2008-04-24 14:55         ` Re: First day of month, last day of month Scott Marlowe <scott.marlowe@gmail.com>
  2008-04-24 15:10           ` Re: First day of month, last day of month Fernando Hevia <fhevia@ip-tel.com.ar>
  2008-04-24 15:16             ` Re: First day of month, last day of month Scott Marlowe <scott.marlowe@gmail.com>
  2008-04-24 15:44               ` Re: First day of month, last day of month Scott Marlowe <scott.marlowe@gmail.com>
@ 2008-04-24 16:07                 ` Fernando Hevia <fhevia@ip-tel.com.ar>
  0 siblings, 0 replies; 21+ messages in thread

From: Fernando Hevia @ 2008-04-24 16:07 UTC (permalink / raw)
  To: 'Scott Marlowe' <scott.marlowe@gmail.com>; +Cc: pgsql-sql

 

> -----Mensaje original-----
> De: Scott Marlowe [mailto:scott.marlowe@gmail.com] 
> 
> 
> Note that if you are storing your time stamp as timestamptz, 
> you can use the "at time zone 'xyz'" construct to create an 
> index, and as long as you retrieve them with the same 
> construct you'll get to use the index.
> 
> create index test_ts_month_trunc on testtable 
> (date_trunc('month',(ts at time zone 'MST'))); 
> select * from testtable 
> where date_trunc('month',(ts at time zone 'MST'))='2007-10-01
00:00:00'::timestamp;
> 

I see the point. Thanks for the elaboration.





^ permalink  raw  reply  [nested|flat] 21+ messages in thread

* Re: First day of month, last day of month
  2008-04-24 12:59 First day of month, last day of month Nacef LABIDI <nacef.l@gmail.com>
  2008-04-24 13:06 ` Re: First day of month, last day of month Frank Bax <fbax@sympatico.ca>
  2008-04-24 13:16   ` Re: First day of month, last day of month Frank Bax <fbax@sympatico.ca>
  2008-04-24 14:15     ` Re: First day of month, last day of month Colin Wetherbee <cww@denterprises.org>
@ 2008-04-24 14:47       ` Bart Degryse <Bart.Degryse@indicator.be>
  2008-04-24 14:52         ` Re: First day of month, last day of month Terry Lee Tucker <terry@chosen-ones.org>
  3 siblings, 1 reply; 21+ messages in thread

From: Bart Degryse @ 2008-04-24 14:47 UTC (permalink / raw)
  To: Colin Wetherbee <cww@denterprises.org>; Nacef LABIDI <nacef.l@gmail.com>; +Cc: pgsql-sql; Frank Bax <fbax@sympatico.ca>

Well, that's what it does afaikt.

>>> "Nacef LABIDI" <nacef.l@gmail.com> 2008-04-24 16:43 >>>
Actually I want to select all rows whith dates between first day of the month 00:00:00 and last date of the month 23:59:59

On Thu, Apr 24, 2008 at 4:15 PM, Colin Wetherbee <cww@denterprises.org> wrote:


Frank Bax wrote:


Frank Bax wrote:


Nacef LABIDI wrote:


is there a better method to retrieve all the rows with dates in the current month.

select * from mytable where extract(month from mydate) = extract(month from now()) and extract(year from mydate) = extract(year from now());

Sorry; I was not thinking clearly - date_trunc is better for this:

select * from mytable where date_trunc('month',mydate) = date_trunc('month',now());

I have some code that uses extract() for this sort of thing.  Would you mind explaining how date_trunc() is better for this?

Most of my extract() results end up in <select> drop-down boxes in HTML.

Thanks.

Colin


-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql 

^ permalink  raw  reply  [nested|flat] 21+ messages in thread

* Re: First day of month, last day of month
  2008-04-24 12:59 First day of month, last day of month Nacef LABIDI <nacef.l@gmail.com>
  2008-04-24 13:06 ` Re: First day of month, last day of month Frank Bax <fbax@sympatico.ca>
  2008-04-24 13:16   ` Re: First day of month, last day of month Frank Bax <fbax@sympatico.ca>
  2008-04-24 14:15     ` Re: First day of month, last day of month Colin Wetherbee <cww@denterprises.org>
  2008-04-24 14:47       ` Re: First day of month, last day of month Bart Degryse <Bart.Degryse@indicator.be>
@ 2008-04-24 14:52         ` Terry Lee Tucker <terry@chosen-ones.org>
  2008-04-24 14:56           ` Re: First day of month, last day of month Scott Marlowe <scott.marlowe@gmail.com>
  2008-04-24 15:07           ` Re: First day of month, last day of month Erik Jones <erik@myemma.com>
  2008-04-24 15:08           ` Re: First day of month, last day of month Bart Degryse <Bart.Degryse@indicator.be>
  0 siblings, 3 replies; 21+ messages in thread

From: Terry Lee Tucker @ 2008-04-24 14:52 UTC (permalink / raw)
  To: pgsql-sql

On Thursday 24 April 2008 10:47, Bart Degryse wrote:
> Well, that's what it does afaikt.

And what does afaikt  mean?
-- 
Terry Lee Tucker
Turbo's IT Manager
Turbo, division of Ozburn-Hessey Logistics
2251 Jesse Jewell Pkwy NE
Gainesville, GA 30501
Tel: (336) 372-6812  Fax: (336) 372-6812  Cell: (336) 404-6987
terry@turbocorp.com
www.turbocorp.com

^ permalink  raw  reply  [nested|flat] 21+ messages in thread

* Re: First day of month, last day of month
  2008-04-24 12:59 First day of month, last day of month Nacef LABIDI <nacef.l@gmail.com>
  2008-04-24 13:06 ` Re: First day of month, last day of month Frank Bax <fbax@sympatico.ca>
  2008-04-24 13:16   ` Re: First day of month, last day of month Frank Bax <fbax@sympatico.ca>
  2008-04-24 14:15     ` Re: First day of month, last day of month Colin Wetherbee <cww@denterprises.org>
  2008-04-24 14:47       ` Re: First day of month, last day of month Bart Degryse <Bart.Degryse@indicator.be>
  2008-04-24 14:52         ` Re: First day of month, last day of month Terry Lee Tucker <terry@chosen-ones.org>
@ 2008-04-24 14:56           ` Scott Marlowe <scott.marlowe@gmail.com>
  2008-04-24 15:08             ` Re: First day of month, last day of month Erik Jones <erik@myemma.com>
  2 siblings, 1 reply; 21+ messages in thread

From: Scott Marlowe @ 2008-04-24 14:56 UTC (permalink / raw)
  To: Terry Lee Tucker <terry@chosen-ones.org>; +Cc: pgsql-sql

On Thu, Apr 24, 2008 at 8:52 AM, Terry Lee Tucker <terry@chosen-ones.org> wrote:
> > On Thursday 24 April 2008 10:47, Bart Degryse wrote:
>
> > Well, that's what it does afaikt.
>
> And what does afaikt mean?

As Far As I Kan Tell?  ???

I'm used to AFAIR, As Far As I Rekall... :)



^ permalink  raw  reply  [nested|flat] 21+ messages in thread

* Re: First day of month, last day of month
  2008-04-24 12:59 First day of month, last day of month Nacef LABIDI <nacef.l@gmail.com>
  2008-04-24 13:06 ` Re: First day of month, last day of month Frank Bax <fbax@sympatico.ca>
  2008-04-24 13:16   ` Re: First day of month, last day of month Frank Bax <fbax@sympatico.ca>
  2008-04-24 14:15     ` Re: First day of month, last day of month Colin Wetherbee <cww@denterprises.org>
  2008-04-24 14:47       ` Re: First day of month, last day of month Bart Degryse <Bart.Degryse@indicator.be>
  2008-04-24 14:52         ` Re: First day of month, last day of month Terry Lee Tucker <terry@chosen-ones.org>
  2008-04-24 14:56           ` Re: First day of month, last day of month Scott Marlowe <scott.marlowe@gmail.com>
@ 2008-04-24 15:08             ` Erik Jones <erik@myemma.com>
  0 siblings, 0 replies; 21+ messages in thread

From: Erik Jones @ 2008-04-24 15:08 UTC (permalink / raw)
  To: Scott Marlowe <scott.marlowe@gmail.com>; +Cc: Terry Lee Tucker <terry@chosen-ones.org>; pgsql-sql


On Apr 24, 2008, at 9:56 AM, Scott Marlowe wrote:

> On Thu, Apr 24, 2008 at 8:52 AM, Terry Lee Tucker <terry@chosen-ones.org 
> > wrote:
>>> On Thursday 24 April 2008 10:47, Bart Degryse wrote:
>>
>>> Well, that's what it does afaikt.
>>
>> And what does afaikt mean?
>
> As Far As I Kan Tell?  ???
>
> I'm used to AFAIR, As Far As I Rekall... :)

Or AFAICS, As Far As I Can See

Erik Jones

DBA | Emma®
erik@myemma.com
800.595.4401 or 615.292.5888
615.292.0777 (fax)

Emma helps organizations everywhere communicate & market in style.
Visit us online at http://www.myemma.com






^ permalink  raw  reply  [nested|flat] 21+ messages in thread

* Re: First day of month, last day of month
  2008-04-24 12:59 First day of month, last day of month Nacef LABIDI <nacef.l@gmail.com>
  2008-04-24 13:06 ` Re: First day of month, last day of month Frank Bax <fbax@sympatico.ca>
  2008-04-24 13:16   ` Re: First day of month, last day of month Frank Bax <fbax@sympatico.ca>
  2008-04-24 14:15     ` Re: First day of month, last day of month Colin Wetherbee <cww@denterprises.org>
  2008-04-24 14:47       ` Re: First day of month, last day of month Bart Degryse <Bart.Degryse@indicator.be>
  2008-04-24 14:52         ` Re: First day of month, last day of month Terry Lee Tucker <terry@chosen-ones.org>
@ 2008-04-24 15:07           ` Erik Jones <erik@myemma.com>
  2 siblings, 0 replies; 21+ messages in thread

From: Erik Jones @ 2008-04-24 15:07 UTC (permalink / raw)
  To: Terry Lee Tucker <terry@chosen-ones.org>; +Cc: pgsql-sql


On Apr 24, 2008, at 9:52 AM, Terry Lee Tucker wrote:

> On Thursday 24 April 2008 10:47, Bart Degryse wrote:
>
> > Well, that's what it does afaikt.
>

afaikt -> as far as I can tell.

Erik Jones

DBA | Emma®
erik@myemma.com
800.595.4401 or 615.292.5888
615.292.0777 (fax)

Emma helps organizations everywhere communicate & market in style.
Visit us online at http://www.myemma.com






^ permalink  raw  reply  [nested|flat] 21+ messages in thread

* Re: First day of month, last day of month
  2008-04-24 12:59 First day of month, last day of month Nacef LABIDI <nacef.l@gmail.com>
  2008-04-24 13:06 ` Re: First day of month, last day of month Frank Bax <fbax@sympatico.ca>
  2008-04-24 13:16   ` Re: First day of month, last day of month Frank Bax <fbax@sympatico.ca>
  2008-04-24 14:15     ` Re: First day of month, last day of month Colin Wetherbee <cww@denterprises.org>
  2008-04-24 14:47       ` Re: First day of month, last day of month Bart Degryse <Bart.Degryse@indicator.be>
  2008-04-24 14:52         ` Re: First day of month, last day of month Terry Lee Tucker <terry@chosen-ones.org>
@ 2008-04-24 15:08           ` Bart Degryse <Bart.Degryse@indicator.be>
  2 siblings, 0 replies; 21+ messages in thread

From: Bart Degryse @ 2008-04-24 15:08 UTC (permalink / raw)
  To: Terry Lee Tucker <terry@chosen-ones.org>; Scott Marlowe <scott.marlowe@gmail.com>; +Cc: pgsql-sql

sory, afaikt vas djust a tiping eror. mi apollogys

>>> "Scott Marlowe" <scott.marlowe@gmail.com> 2008-04-24 16:56 >>>
On Thu, Apr 24, 2008 at 8:52 AM, Terry Lee Tucker <terry@chosen-ones.org> wrote:
> > On Thursday 24 April 2008 10:47, Bart Degryse wrote:
>
> > Well, that's what it does afaikt.
>
> And what does afaikt mean?

As Far As I Kan Tell?  ???

I'm used to AFAIR, As Far As I Rekall... :)

-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql

^ permalink  raw  reply  [nested|flat] 21+ messages in thread

* Re: First day of month, last day of month
  2008-04-24 12:59 First day of month, last day of month Nacef LABIDI <nacef.l@gmail.com>
@ 2008-04-24 13:15 ` A. Kretschmer <andreas.kretschmer@schollglas.com>
  2008-04-24 16:39   ` Re: First day of month, last day of month Nacef LABIDI <nacef.l@gmail.com>
  1 sibling, 1 reply; 21+ messages in thread

From: A. Kretschmer @ 2008-04-24 13:15 UTC (permalink / raw)
  To: pgsql-sql

am  Thu, dem 24.04.2008, um 14:59:47 +0200 mailte Nacef LABIDI folgendes:
> Hi all,
> 
> I want to select data from a table according to a date column in my table. I
> want to select all the rows which have date in the current month. So is there a
> way to get from the actual date the first day and the last day of the month or

test=*# select date_trunc('month', current_date), date_trunc('month', current_date)+'1month'::interval-'1day'::interval;
       date_trunc       |        ?column?
------------------------+------------------------
 2008-04-01 00:00:00+02 | 2008-04-30 00:00:00+02



-- 
Andreas Kretschmer
Kontakt:  Heynitz: 035242/47150,   D1: 0160/7141639 (mehr: -> Header)
GnuPG-ID:   0x3FFF606C, privat 0x7F4584DA   http://wwwkeys.de.pgp.net



^ permalink  raw  reply  [nested|flat] 21+ messages in thread

* Re: First day of month, last day of month
  2008-04-24 12:59 First day of month, last day of month Nacef LABIDI <nacef.l@gmail.com>
  2008-04-24 13:15 ` Re: First day of month, last day of month A. Kretschmer <andreas.kretschmer@schollglas.com>
@ 2008-04-24 16:39   ` Nacef LABIDI <nacef.l@gmail.com>
  0 siblings, 0 replies; 21+ messages in thread

From: Nacef LABIDI @ 2008-04-24 16:39 UTC (permalink / raw)
  To: A. Kretschmer <andreas.kretschmer@schollglas.com>; +Cc: pgsql-sql

It would be rather :

test=*# select date_trunc('month', current_date), date_trunc('month',
current_date)+'1month':
>
> :interval-'1sec'::interval;


"2008-04-01 00:00:00+02";"2008-04-30 23:59:59+02"


On Thu, Apr 24, 2008 at 3:15 PM, A. Kretschmer <
andreas.kretschmer@schollglas.com> wrote:

> am  Thu, dem 24.04.2008, um 14:59:47 +0200 mailte Nacef LABIDI folgendes:
> > Hi all,
> >
> > I want to select data from a table according to a date column in my
> table. I
> > want to select all the rows which have date in the current month. So is
> there a
> > way to get from the actual date the first day and the last day of the
> month or
>
> test=*# select date_trunc('month', current_date), date_trunc('month',
> current_date)+'1month'::interval-'1day'::interval;
>       date_trunc       |        ?column?
> ------------------------+------------------------
>  2008-04-01 00:00:00+02 | 2008-04-30 00:00:00+02
>
>
>
> --
> Andreas Kretschmer
> Kontakt:  Heynitz: 035242/47150,   D1: 0160/7141639 (mehr: -> Header)
> GnuPG-ID:   0x3FFF606C, privat 0x7F4584DA   http://wwwkeys.de.pgp.net
>
> --
> Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-sql
>

^ permalink  raw  reply  [nested|flat] 21+ messages in thread


end of thread, other threads:[~2008-04-24 16:39 UTC | newest]

Thread overview: 21+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2008-04-24 12:59 First day of month, last day of month Nacef LABIDI <nacef.l@gmail.com>
2008-04-24 13:06 ` Frank Bax <fbax@sympatico.ca>
2008-04-24 13:11   ` Bart Degryse <Bart.Degryse@indicator.be>
2008-04-24 13:16   ` Frank Bax <fbax@sympatico.ca>
2008-04-24 14:15     ` Colin Wetherbee <cww@denterprises.org>
2008-04-24 14:41       ` Erik Jones <erik@myemma.com>
2008-04-24 14:42       ` Bart Degryse <Bart.Degryse@indicator.be>
2008-04-24 14:43       ` Nacef LABIDI <nacef.l@gmail.com>
2008-04-24 14:55         ` Scott Marlowe <scott.marlowe@gmail.com>
2008-04-24 15:10           ` Fernando Hevia <fhevia@ip-tel.com.ar>
2008-04-24 15:16             ` Scott Marlowe <scott.marlowe@gmail.com>
2008-04-24 15:44               ` Scott Marlowe <scott.marlowe@gmail.com>
2008-04-24 16:07                 ` Fernando Hevia <fhevia@ip-tel.com.ar>
2008-04-24 14:47       ` Bart Degryse <Bart.Degryse@indicator.be>
2008-04-24 14:52         ` Terry Lee Tucker <terry@chosen-ones.org>
2008-04-24 14:56           ` Scott Marlowe <scott.marlowe@gmail.com>
2008-04-24 15:08             ` Erik Jones <erik@myemma.com>
2008-04-24 15:07           ` Erik Jones <erik@myemma.com>
2008-04-24 15:08           ` Bart Degryse <Bart.Degryse@indicator.be>
2008-04-24 13:15 ` A. Kretschmer <andreas.kretschmer@schollglas.com>
2008-04-24 16:39   ` Nacef LABIDI <nacef.l@gmail.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox