Re: First day of month, last day of month

Поиск
Список
Период
Сортировка
От Colin Wetherbee
Тема Re: First day of month, last day of month
Дата
Msg-id 481095FB.7090600@denterprises.org
обсуждение исходный текст
Ответ на Re: First day of month, last day of month  (Frank Bax <fbax@sympatico.ca>)
Ответы Re: First day of month, last day of month  (Erik Jones <erik@myemma.com>)
Re: First day of month, last day of month  ("Bart Degryse" <Bart.Degryse@indicator.be>)
Re: First day of month, last day of month  ("Nacef LABIDI" <nacef.l@gmail.com>)
Список 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



В списке pgsql-sql по дате отправления:

Предыдущее
От: Volkan YAZICI
Дата:
Сообщение: Re: How I can check a substring is a valid number in postgresql ?
Следующее
От: Erik Jones
Дата:
Сообщение: Re: First day of month, last day of month