Re: [GENERAL] Convert TimeStamp to Date

From: Dmitry Tkach <dmitry(at)openratings(dot)com>
To: Claudio Lapidus <clapidus(at)hotmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org, Ron Johnson <ron(dot)l(dot)johnson(at)cox(dot)net>, shuai(at)objectwareinc(dot)com, pgsql-bugs(at)postgresql(dot)org
Subject: Re: [GENERAL] Convert TimeStamp to Date
Date: 2003-07-23 20:52:54
Message-ID: 3F1EF5A6.3010809@openratings.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-general

Yep ... looks like it got broken in 7.3.
7.2.4 works fine, but 7.3 (and CVS tip) doesn't.

This is because in 7.2, timestamp_date () and timestamptz_date () do the
same thing -
convert the time to Julian date and then subtruct the offset for Y2K,
and both work.

In 7.3 (and 7.4) timestamptz_date () is still doing that (and select
'1999-12-31 00:00:01'::timestamptz::date still works),
*but* timestamp_date() is changed for some reason to just divide the
timestamp by the number of microseconds per day, that is obviously wrong
for the case when ts is negative (before 2000) because integer division
(unlike floor ()) truncates towards zero...

I'd send the patch... but just thought I would better be done by someone
who knows the reason why that function had changed to begin with...

Dima

Claudio Lapidus wrote:

>>template1=# insert into t values ('1993-08-10 17:48:41');
>>INSERT 16980 1
>>
>>
>So we are talking about August 10th, right?
>
>
>
>>template1=# select f1, date(f1), f1::date, cast(f1 as date) from t;
>> f1 | date | f1 | f1
>>---------------------+------------+------------+------------
>> 1993-08-10 17:48:41 | 1993-08-11 | 1993-08-11 | 1993-08-11
>>(1 row)
>>
>>
>Here all casts give Aug. 11th, same as on my 7.3.2 (tested right now). This
>is one day *more* than expected, not 'the previous date' as the original
>poster said. Perhaps some sort of rounding here?
>
>cl.
>
>---------------------------(end of broadcast)---------------------------
>TIP 8: explain analyze is your friend
>
>

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Ron Johnson 2003-07-23 22:17:01 Re: Convert TimeStamp to Date
Previous Message Claudio Lapidus 2003-07-23 19:28:56 Re: Convert TimeStamp to Date

Browse pgsql-general by date

  From Date Subject
Next Message Rob Sell 2003-07-23 20:55:06 Re: Join Problem
Previous Message Network Administrator 2003-07-23 20:47:21 Re: birthday calculation