Re: Inconsistant DOW... - Mailing list pgsql-general

From Richard Huxton
Subject Re: Inconsistant DOW...
Date
Msg-id 40E04EFB.2050407@archonet.com
Whole thread Raw
In response to Inconsistant DOW...  ("W.B.Hill" <bill@hillzaa1.miniserver.com>)
Responses Re: Inconsistant DOW...  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
W.B.Hill wrote:
> Hiya!
>
> What's happening, where've I goofed?
>
> CREATE TABLE test (d date);
[snip]
>
> This is good - every Easter's on a Sunday so far...
>
> SELECT d+'45 days ago'::interval FROM test;
>         ?column?
> ------------------------
>  2004-02-25 23:00:00+00
>  2005-02-10 00:00:00+00
>  2006-03-01 23:00:00+00
>  2007-02-21 23:00:00+00
>  2008-02-07 00:00:00+00
>  2009-02-25 23:00:00+00
>  2010-02-17 23:00:00+00
> (7 rows)
>
> Why the different times??? Why the times???

At a guess, the date is being converted into a timestamp with timezone
so you can add the interval to it. At another guess, the 1hr difference
is due to the effects of daylight-savings-time (or whatever it's called
in your locale).

I've got a feeling '45 days'==45*'24 hours' which, going over a DST
boundary isn't true for one day. Simplest solution would probably be to
add a few hours to the date before doing your calculations and then
casting back to a date.

--
   Richard Huxton
   Archonet Ltd

pgsql-general by date:

Previous
From: Adam Ruth
Date:
Subject: Re: Group by - Case insensitivity
Next
From: Patrick Welche
Date:
Subject: Re: Inconsistant DOW...