Search Postgresql Archives

Re: getting last day of month

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

 



egy@xxxxxxxxxx (Sergey Pariev) writes:
> I need to find out the last day of current month. Currently I do the
> trick with code below, but that's rather ugly way to do it IMHO. Could
> anybody suggest me a better way ?


log_analysis=# select date_trunc('months', (date_trunc('months', now()) + '45 days'::interval)) - '1 day'::interval;
        ?column?        
------------------------
 2005-08-31 00:00:00+00
(1 row)

So...

log_analysis=# create or replace function eom (timestamptz) returns timestamptz as '
log_analysis'# select date_trunc(''months'', (date_trunc(''months'', $1) + ''45 days''::interval)) - ''1 day''::interval;' language sql;
CREATE FUNCTION
log_analysis=# select eom(now());
          eom           
------------------------
 2005-08-31 00:00:00+00
(1 row)
log_analysis=# select eom('2004-07-02');
          eom           
------------------------
 2004-07-31 00:00:00+00
(1 row)

log_analysis=# select eom('2004-02-29');
          eom           
------------------------
 2004-02-29 00:00:00+00
(1 row)
log_analysis=# select eom('2004-02-29'), eom('2005-02-28'), eom('2005-03-01');
          eom           |          eom           |          eom           
------------------------+------------------------+------------------------
 2004-02-29 00:00:00+00 | 2005-02-28 00:00:00+00 | 2005-03-31 00:00:00+00
(1 row)
-- 
let name="cbbrowne" and tld="cbbrowne.com" in name ^ "@" ^ tld;;
http://www3.sympatico.ca/cbbrowne/emacs.html
Q: How many Newtons does it take to change a light bulb?
A: Faux!  There to eat lemons, axe gravy soup!

---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
       subscribe-nomail command to majordomo@xxxxxxxxxxxxxx so that your
       message can get through to the mailing list cleanly

[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