Re: to_char(date '2001-04-01', 'dd') results in 31 -- why?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Fred Yankowski <fred(at)ontosys(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: to_char(date '2001-04-01', 'dd') results in 31 -- why?
Date: 2001-01-14 16:50:08
Message-ID: 26195.979491008@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Fred Yankowski <fred(at)ontosys(dot)com> writes:
> In PostgreSQL 7.0.3 (on NT), the expression
> to_char(date '2001-04-01', 'dd')
> evaluates to '31', which is a bit surprising.

It's just a bug: date to timestamp conversion did the wrong thing on
DST forward transition days in 7.0.3 and before. It's fixed for 7.1.

In EST5EDT time zone, 7.0.* gives:

play=> select timestamp(date '2001-03-31') ;
timestamp
------------------------
2001-03-31 00:00:00-05 -- correct
(1 row)

play=> select timestamp(date '2001-04-01') ;
timestamp
------------------------
2001-03-31 23:00:00-05 -- off by 1 hour
(1 row)

play=> select timestamp(date '2001-04-02') ;
timestamp
------------------------
2001-04-02 00:00:00-04 -- correct
(1 row)

but current sources (7.1beta3) give:

regression=# select timestamp(date '2001-03-31') ;
timestamp
------------------------
2001-03-31 00:00:00-05
(1 row)

regression=# select timestamp(date '2001-04-01') ;
timestamp
------------------------
2001-04-01 00:00:00-05
(1 row)

regression=# select timestamp(date '2001-04-02') ;
timestamp
------------------------
2001-04-02 00:00:00-04
(1 row)

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Thomas T. Thai 2001-01-14 17:29:18 Re: performance hit with --enable-debug
Previous Message Tom Lane 2001-01-14 16:31:18 Re: fatal error - different CATALOG_VERSION_NO