Re: inverse of "day of year" - Mailing list pgsql-sql

From Tom Lane
Subject Re: inverse of "day of year"
Date
Msg-id 24189.1079709005@sss.pgh.pa.us
Whole thread Raw
In response to Re: inverse of "day of year"  (Robert Creager <Robert_Creager@LogicalChaos.org>)
Responses Re: inverse of "day of year"  (Martin Marques <martin@bugs.unl.edu.ar>)
List pgsql-sql
Robert Creager <Robert_Creager@LogicalChaos.org> writes:
> Martin Marques <martin@bugs.unl.edu.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


pgsql-sql by date:

Previous
From: Devrim GUNDUZ
Date:
Subject: Re: psql: FATAL 1: IDENT authentication failed for user error
Next
From: Tom Lane
Date:
Subject: Re: psql: FATAL 1: IDENT authentication failed for user error - Urgent pls