Re: First day of month, last day of month

From: "Nacef LABIDI" <nacef(dot)l(at)gmail(dot)com>
To: "Colin Wetherbee" <cww(at)denterprises(dot)org>
Cc: "Frank Bax" <fbax(at)sympatico(dot)ca>, pgsql-sql(at)postgresql(dot)org
Subject: Re: First day of month, last day of month
Date: 2008-04-24 14:43:40
Message-ID: f16f7ea00804240743la32b08cm6ced0d9ced56948a@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)denterprises(dot)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(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-sql
>

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Bart Degryse 2008-04-24 14:47:14 Re: First day of month, last day of month
Previous Message Bart Degryse 2008-04-24 14:42:26 Re: First day of month, last day of month