Search Postgresql Archives

R: find last day of month

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



>> "Andrus Moor" <eetasoft@xxxxxxxxx> writes:
>> 
>>> I have a table containing month column in format mm.yyyy
>>> 
>>> create table months ( tmkuu c(7));
>>> insert into months values ('01.2005');
>>> insert into months values ('02.2005');
>>> 
>>> How to create select statement which converts this column to date
>>> type containing last day of month like
>>> 
>>> '2005-01-31'
>>> '2005-02-28'
>> 
>> The usual trick is to split it into year and month, add 1 to the
>> month, if that's > 12, jump to 1, and add a year.
>> 
>> Based on those...  Construct the first day of the NEXT month.

Try this (my date is current_date):
select date_trunc('month', current_date + '1 month'::interval) - '1 day'::interval

-------------------------------------------
Bastianello Luciano - MBS CP Development
Software Consultant - Apprentice Sorcerer
http://community.visual-basic.it/LucianoB/
e-mail: lbastianello@xxxxxxxx
MSN: cteniza@xxxxxxxxxxx - ICQ: 209754422
AIM: lubastia - YAHOO lbastianello
-------------------------------------------



	

	
		
___________________________________ 
Yahoo! Mail: gratis 1GB per i messaggi e allegati da 10MB 
http://mail.yahoo.it


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux