Re: subtract a day from the NOW function - Mailing list pgsql-sql

From Michael Glaesemann
Subject Re: subtract a day from the NOW function
Date
Msg-id C6AE494E-146A-443E-9E54-AE95F2943B1F@seespotcode.net
Whole thread Raw
In response to Re: subtract a day from the NOW function  (Steve Crawford <scrawford@pinpointresearch.com>)
List pgsql-sql
On Jun 7, 2007, at 16:07 , Steve Crawford wrote:

> On 8.2 I'm seeing an adjustment if the DST adjustment includes  
> units of
> "day" or greater (ie. '1 day' and '1 day 01:00' get adjusted but '24
> hours' and '25 hours' do not).
>
> But PG doesn't follow the same rules in subtracting timestamptz values
> so operations involving timestamps and intervals are (sometimes) not
> reversible:

Right. It's only for timestamptz +/i interval.

> select timestamptz '2007-11-05' - timestamptz '2007-11-04';
>
>     ?column?
> ----------------
>  1 day 01:00:00

It is a bit tricky. Datetime math is inherently so.

> select timestamptz '2007-11-04' + interval '1 day 01:00:00';
>         ?column?
> ------------------------
>  2007-11-05 01:00:00-08

What PostgreSQL is doing behind the scenes is incrementing the date  
2007-11-04 ahead 1 day and 1 hour. It treats months (and years),  
days, and time separately.

Michael Glaesemann
grzm seespotcode net




pgsql-sql by date:

Previous
From: Michael Glaesemann
Date:
Subject: Re: subtract a day from the NOW function
Next
From: Tom Lane
Date:
Subject: Re: subtract a day from the NOW function