Re: What's wrong with my date/interval arithmetic?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Wojtek <wojtg(at)polbox(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: What's wrong with my date/interval arithmetic?
Date: 2004-03-02 15:03:06
Message-ID: 27414.1078239786@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Wojtek <wojtg(at)polbox(dot)com> writes:
> Investigating that a little further I found out that there is a difference
> in results returned by age:

> select age(cast(to_timestamp('2003-12-01 03:50:45','YYYY-MM-dd HH24:MI:SS') as timestamp),
> cast(to_timestamp('2003-10-17 23:07:00','YYYY-MM-dd HH24:MI:SS') as timestamp))
> is '1 mon 14 days 04:43:45'

> and

> select age(to_timestamp('2003-12-01 03:50:45','YYYY-MM-dd HH24:MI:SS'),
> to_timestamp('2003-10-17 23:07:00','YYYY-MM-dd HH24:MI:SS'))
> is '1 mon 13 days 04:43:45'

I get '1 mon 14 days 04:43:45' and '1 mon 14 days 05:43:45'
respectively. This is a reasonable result for my timezone (EST5EDT),
because there is a daylight-savings transition involved:

regression=# select to_timestamp('2003-12-01 03:50:45','YYYY-MM-dd HH24:MI:SS');
to_timestamp
------------------------
2003-12-01 03:50:45-05
(1 row)

regression=# select to_timestamp('2003-10-17 23:07:00','YYYY-MM-dd HH24:MI:SS');
to_timestamp
------------------------
2003-10-17 23:07:00-04
(1 row)

Note the October date is taken as GMT-4, the December GMT-5. The hour
gained in the fall DST transition is accounted for when doing
timezone-aware arithmetic, but not when doing timezone-free arithmetic.

I still think the behavior you see is related to the timezone you're
using, which you still haven't told us. Also, what PG version are you
running, and on what platform?

regards, tom lane

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Greg Patnude 2004-03-02 16:23:16 Re: User defined types -- Social Security number...
Previous Message Wojtek 2004-03-02 07:00:46 Re: What's wrong with my date/interval arithmetic?