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

From Tom Lane
Subject Re: to_char(date '2001-04-01', 'dd') results in 31 -- why?
Date
Msg-id 26195.979491008@sss.pgh.pa.us
Whole thread Raw
In response to to_char(date '2001-04-01', 'dd') results in 31 -- why?  (Fred Yankowski <fred@ontosys.com>)
List pgsql-general
Fred Yankowski <fred@ontosys.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

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: fatal error - different CATALOG_VERSION_NO
Next
From: "Thomas T. Thai"
Date:
Subject: Re: performance hit with --enable-debug