Re: subtract a day from the NOW function

From: Michael Glaesemann <grzm(at)seespotcode(dot)net>
To: Steve Crawford <scrawford(at)pinpointresearch(dot)com>
Cc: Scott Marlowe <smarlowe(at)g2switchworks(dot)com>, "Campbell, Lance" <lance(at)uiuc(dot)edu>, pgsql-sql(at)postgresql(dot)org
Subject: Re: subtract a day from the NOW function
Date: 2007-06-07 19:22:44
Message-ID: D3436F83-5008-4CA3-B056-E792654B4F73@seespotcode.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-sql


On Jun 7, 2007, at 13:58 , Steve Crawford wrote:

> Beware in the "or something like that category" that PostgreSQL
> considers "1 day" to be "24 hours"

Actually, recent versions of PostgreSQL take into account daylight
saving time in accordance with the current PostgreSQL time zone
setting, so '1 day' in the context of timestamptz +/- interval may
be 23, 24, or 25 hours.

test=# select version();

version
------------------------------------------------------------------------
----------------------------------------------------------------------
PostgreSQL 8.2.4 on powerpc-apple-darwin8.9.0, compiled by GCC
powerpc-apple-darwin8-gcc-4.0.1 (GCC) 4.0.1 (Apple Computer, Inc.
build 5367)
(1 row)

test=# select '2007-03-12'::timestamptz, '2007-03-12'::timestamptz -
interval '1 day';
timestamptz | ?column?
------------------------+------------------------
2007-03-12 00:00:00-05 | 2007-03-11 00:00:00-06
(1 row)

test=# select '2007-11-04'::timestamptz, '2007-11-04'::timestamptz -
interval '1 day';
timestamptz | ?column?
------------------------+------------------------
2007-11-04 00:00:00-05 | 2007-11-03 00:00:00-05
(1 row)

test=# select '2007-11-04'::timestamptz, '2007-11-04'::timestamptz +
interval '1 day';
timestamptz | ?column?
------------------------+------------------------
2007-11-04 00:00:00-05 | 2007-11-05 00:00:00-06
(1 row)

test=# show time zone;
TimeZone
------------
US/Central
(1 row)

Note how the UTC offset changes across the daylight saving time change.

Michael Glaesemann
grzm seespotcode net

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Jeff Ross 2007-06-07 19:25:25 Re: Generate random password
Previous Message Guy Fraser 2007-06-07 19:20:43 Re: Creditcard Number Security was Re: Encrypted column

Browse pgsql-sql by date

  From Date Subject
Next Message Fernando Hevia 2007-06-07 20:38:47 Re: subtract a day from the NOW function
Previous Message Steve Crawford 2007-06-07 18:58:38 Re: subtract a day from the NOW function