| From: | Colin Wetherbee <cww(at)denterprises(dot)org> |
|---|---|
| To: | Frank Bax <fbax(at)sympatico(dot)ca> |
| Cc: | pgsql-sql(at)postgresql(dot)org |
| Subject: | Re: First day of month, last day of month |
| Date: | 2008-04-24 14:15:23 |
| Message-ID: | 481095FB.7090600@denterprises.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | 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
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Erik Jones | 2008-04-24 14:41:04 | Re: First day of month, last day of month |
| Previous Message | Volkan YAZICI | 2008-04-24 13:53:15 | Re: How I can check a substring is a valid number in postgresql ? |