From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Robert Creager <Robert_Creager(at)LogicalChaos(dot)org> |
Cc: | Martin Marques <martin(at)bugs(dot)unl(dot)edu(dot)ar>, pgsql-sql(at)postgresql(dot)org |
Subject: | Re: inverse of "day of year" |
Date: | 2004-03-19 15:10:05 |
Message-ID: | 24189.1079709005@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Robert Creager <Robert_Creager(at)LogicalChaos(dot)org> writes:
> Martin Marques <martin(at)bugs(dot)unl(dot)edu(dot)ar> confessed:
>> Is there a function that would give me the date for a given day of year?
> Something like:
> select date_trunc( 'year', now() ) + (extract( doy from now() ) - 1) *
> '1day'::interval;
timestamp + interval arithmetic is likely to give you problems at
daylight savings boundaries, since '1day' will be taken as '24hours'.
A more reliable way to get (what I assume is) the desired result is
to use the date + integer operator:
select date_trunc('year', now())::date + (extract(doy from now()) - 1)::integer;
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2004-03-19 15:12:11 | Re: psql: FATAL 1: IDENT authentication failed for user error - Urgent pls |
Previous Message | Devrim GUNDUZ | 2004-03-19 14:23:10 | Re: psql: FATAL 1: IDENT authentication failed for user error |