Re: Date trunc in UTC - Mailing list pgsql-sql

From Tom Lane
Subject Re: Date trunc in UTC
Date
Msg-id 23923.1037977842@sss.pgh.pa.us
Whole thread Raw
In response to Re: Date trunc in UTC  (Thrasher <thrasher@fibers.upc.es>)
List pgsql-sql
Thrasher <thrasher@fibers.upc.es> writes:
> The biggest point that I see is that it would be nice to have some kind 
> of function that works with UTC values, regarding of which timezone the 
> user has set.

You can do that in 7.3, using the AT TIME ZONE construct.  Observe:

regression-# begin;
BEGIN
regression=# select now();             now
-------------------------------2002-11-22 09:59:48.706508-05            'now' in local time (EST)
(1 row)

regression=# select now() at time zone 'UTC';         timezone
----------------------------2002-11-22 14:59:48.706508            'now' in UTC
(1 row)

regression=# select date_trunc('month', now() at time zone 'UTC');    date_trunc
---------------------2002-11-01 00:00:00                month start in UTC
(1 row)

regression=# select date_trunc('month', now() at time zone 'UTC') at time zone 'UTC';       timezone
------------------------2002-10-31 19:00:00-05                month start in local time
(1 row)

regression=# commit;

This is a tad bulky maybe, but it'd be easy to wrap up in a user-defined
function.

AT TIME ZONE was less functional, and very poorly documented, in 7.2.
The 7.3 version is described at
http://developer.postgresql.org/docs/postgres/functions-datetime.html#FUNCTIONS-DATETIME-ZONECONVERT
        regards, tom lane


pgsql-sql by date:

Previous
From: Dan Langille
Date:
Subject: Re: calculating interval
Next
From: Jean-Luc Lachance
Date:
Subject: Re: calculating interval