Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 6D4704758FE for ; Fri, 22 Nov 2002 10:12:47 -0500 (EST) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by postgresql.org (Postfix) with ESMTP id 75505475461 for ; Fri, 22 Nov 2002 10:12:46 -0500 (EST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.6/8.12.6) with ESMTP id gAMFAgsX023924; Fri, 22 Nov 2002 10:10:43 -0500 (EST) To: Thrasher Cc: Richard Huxton , pgsql-sql@postgresql.org, Thomas Lockhart Subject: Re: Date trunc in UTC In-reply-to: <3DDDF4AD.8030105@fibers.upc.es> References: <3DDB5991.9060706@fibers.upc.es> <200211201306.47345.dev@archonet.com> <3DDBAD02.3090406@electronic-group.com> <200211211015.42013.dev@archonet.com> <11965.1037892419@sss.pgh.pa.us> <3DDDF4AD.8030105@fibers.upc.es> Comments: In-reply-to Thrasher message dated "Fri, 22 Nov 2002 10:11:09 +0100" Date: Fri, 22 Nov 2002 10:10:42 -0500 Message-ID: <23923.1037977842@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200211/345 X-Sequence-Number: 10487 Thrasher 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