pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedGetting yyyy-mm-dd 00:00:00 in an arbitrary time zone
3+ messages / 2 participants
[nested] [flat]
* Getting yyyy-mm-dd 00:00:00 in an arbitrary time zone
@ 2006-03-04 00:13 Davidson, Robert <robdavid@amazon.com>
2006-03-04 00:32 ` Re: Getting yyyy-mm-dd 00:00:00 in an arbitrary time zone Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 3+ messages in thread
From: Davidson, Robert @ 2006-03-04 00:13 UTC (permalink / raw)
To: pgsql-sql
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.
extract is slightly more promising:
select extract(DAY from '2005-12-31 23:00:00-800' at time zone 'CST')
1
This returns the correct day, so all I have to do is glue it back together in the right time zone:
select to_timestamp(extract(YEAR from '2005-12-31 23:00:00-800' at time zone 'CST')||'-'||
extract(MONTH from '2005-12-31 23:00:00-800' at time zone 'CST')||'-'||
extract(DAY from '2005-12-31 23:00:00-800' at time zone 'CST')||' 00:00:00 CST', 'YYYY-MM-DD HH:MI:SS TZ')
ERROR: "TZ"/"tz" not supported
Has anyone solved this problem before?
Many thanks,
Robert
Select version()
PostgreSQL 8.1.3 on i686-pc-linux-gnu, compiled by GCC 2.95.3
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Getting yyyy-mm-dd 00:00:00 in an arbitrary time zone
2006-03-04 00:13 Getting yyyy-mm-dd 00:00:00 in an arbitrary time zone Davidson, Robert <robdavid@amazon.com>
@ 2006-03-04 00:32 ` Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 3+ messages in thread
From: Tom Lane @ 2006-03-04 00:32 UTC (permalink / raw)
To: Davidson, Robert <robdavid@amazon.com>; +Cc: pgsql-sql
"Davidson, Robert" <robdavid@amazon.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
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Getting yyyy-mm-dd 00:00:00 in an arbitrary time zone
@ 2006-03-04 04:34 Davidson, Robert <robdavid@amazon.com>
0 siblings, 0 replies; 3+ messages in thread
From: Davidson, Robert @ 2006-03-04 04:34 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: 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@sss.pgh.pa.us]
Sent: Friday, March 03, 2006 4:32 PM
To: Davidson, Robert
Cc: pgsql-sql@postgresql.org
Subject: Re: [SQL] Getting yyyy-mm-dd 00:00:00 in an arbitrary time zone
"Davidson, Robert" <robdavid@amazon.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
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2006-03-04 04:34 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2006-03-04 00:13 Getting yyyy-mm-dd 00:00:00 in an arbitrary time zone Davidson, Robert <robdavid@amazon.com>
2006-03-04 00:32 ` Tom Lane <tgl@sss.pgh.pa.us>
2006-03-04 04:34 Re: Getting yyyy-mm-dd 00:00:00 in an arbitrary time zone Davidson, Robert <robdavid@amazon.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox