Re: Calendar Function - Mailing list pgsql-sql

From Jeff Boes
Subject Re: Calendar Function
Date
Msg-id cttvkv$114u$1@news.hub.org
Whole thread Raw
In response to Re: Calendar Function  ("Muhyiddin A.M Hayat" <middink@indo.net.id>)
List pgsql-sql
Muhyiddin A.M Hayat wrote:
> Ok, thanks
>  
> But if i would like to display date in one Month,
>  
>  e.g :
> date in feb 2005

You can do that in Pg date arithmetic:

# select '1 oct 2004'::date + '1 month'::interval - '1 day'::interval;      ?column?
--------------------- 2004-10-31 00:00:00
(1 row)

# select '1 nov 2004'::date + '1 month'::interval - '1 day'::interval;      ?column?
--------------------- 2004-11-30 00:00:00
(1 row)

# select '1 feb 2004'::date + '1 month'::interval - '1 day'::interval;      ?column?
--------------------- 2004-02-29 00:00:00
(1 row)


Thus, given the original response to your question:

select * from calendar('1 feb 2004', ( '1 feb 2004'::date +
'1 month'::interval - '1 day'::interval )::date);


-- 
Jeff Boes                                      vox 269.226.9550 ext 24
http://www.nexcerpt.com                        fax 269.349.9076
           ...Nexcerpt... Extend your Expertise


pgsql-sql by date:

Previous
From: "Joel Fradkin"
Date:
Subject: Re: problem with backup and restore (probaly stupit newb thing)
Next
From: Karsten Hilbert
Date:
Subject: Re: Information about the command SQL " create synonym".