Re: Getting yyyy-mm-dd 00:00:00 in an arbitrary time zone

From: "Davidson, Robert" <robdavid(at)amazon(dot)com>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Getting yyyy-mm-dd 00:00:00 in an arbitrary time zone
Date: 2006-03-04 04:34:58
Message-ID: D224B13DA625924883A3B024CD6608F001B0C51A@exchg-sea5-03.ant.amazon.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

It does, doesn't it. And it does it just the way it is documented in 9.9.3 AT TIME ZONE table 9.27.

I was expecting it to be harder and didn't see I had figured out the right answer already - thanks!

Robert

-----Original Message-----
From: Tom Lane [mailto:tgl(at)sss(dot)pgh(dot)pa(dot)us]
Sent: Friday, March 03, 2006 4:32 PM
To: Davidson, Robert
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: [SQL] Getting yyyy-mm-dd 00:00:00 in an arbitrary time zone

"Davidson, Robert" <robdavid(at)amazon(dot)com> writes:
> I am trying to find out what the last full day of data for an
> arbitrary = timezone (generally not the pg client's timezone). I get
> the = max(timestamp), then would like to remove the time portion.
> Sounded like = a job for date_trunc, unfortunately date_trunc is not timezone aware:

> select (date_trunc('day', '2006-01-31 23:00:00-800' at time zone
> 'CST')) = at time zone 'CST'
> 2006-01-31 22:00:00-08

> Since the client is in PST, the truncated date is returned as
> 2006-02-01 = PST which is two hours before the desired time.

You're being quite unclear about what you want, but AFAICS the above expression does exactly what you asked for. Namely, you get a time that is midnight in the CST zone and then is adjusted to your current timezone for display.

Perhaps you could be more clear about why you don't like this result?

regards, tom lane

Browse pgsql-sql by date

  From Date Subject
Next Message Nikolay Samokhvalov 2006-03-04 19:07:20 Re: Sequential scan where Index scan expected.
Previous Message Tom Lane 2006-03-04 00:32:25 Re: Getting yyyy-mm-dd 00:00:00 in an arbitrary time zone