X-Original-To: pgsql-php-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 4909252AF8 for ; Wed, 20 Jul 2005 22:12:39 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 13063-03 for ; Thu, 21 Jul 2005 01:12:35 +0000 (GMT) Received: from tomts25-srv.bellnexxia.net (tomts25.bellnexxia.net [209.226.175.188]) by svr1.postgresql.org (Postfix) with ESMTP id C158852AE0 for ; Wed, 20 Jul 2005 22:12:33 -0300 (ADT) Received: from [192.168.200.100] ([69.158.4.60]) by tomts25-srv.bellnexxia.net (InterMail vM.5.01.06.10 201-253-122-130-110-20040306) with ESMTP id <20050721011237.XWVH27245.tomts25-srv.bellnexxia.net@[192.168.200.100]>; Wed, 20 Jul 2005 21:12:37 -0400 User-Agent: Microsoft-Entourage/10.1.4.030702.0 Date: Wed, 20 Jul 2005 21:12:31 -0400 Subject: Re: Times and time zones From: Lynna Landstreet To: Frank Bax , PgSQL-PHP Mailing List Message-ID: In-Reply-To: <5.2.1.1.0.20050720193421.03ef54d0@pop6.sympatico.ca> Mime-version: 1.0 Content-type: text/plain; charset="US-ASCII" Content-transfer-encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests= X-Spam-Level: X-Archive-Number: 200507/21 X-Sequence-Number: 3209 On 7/20/05 7:36 PM, Frank Bax wrote: >> I've set the datatype for all the time/date columns to timestamp with time >> zone, as it seems to be the only type that will store all the data I need, >> but I was thrown a bit by the fact that PostgreSQL apparently then converts >> all the times to GMT, setting the time zone to +00 accordingly. So if a user >> enters July 20, 2005, 6:30 pm EDT (Eastern daylight savings time), it's >> saved as 2005-07-20 22:30:00+00 rather than 2005-07-20 18:30:00-04. >> >> Now, this is fine for comparing different times internally, but it's not so >> good for outputting the times back to the user for them to view and edit. >> I've now created a second column for each time which saves the time zone >> they originally entered, but I'm having trouble converting the time back >> from GMT to the original. I need to write a PHP function > > Why use php when sql will do the job? > > http://www.postgresql.org/docs/7.4/interactive/functions-datetime.html#FUNCTIO > NS-DATETIME-ZONECONVERT Aaagh! Can't believe I missed that! Thank you! So to use this, I'd just add it to my select statement when retrieving the data? As in "SELECT TIMESTAMP WITH TIME ZONE arrival_time AT TIME ZONE arrival_time_zone, [and various other fields] FROM [table] WHERE [condition]"? And for the time zone value, can it take all the input types listed for timezone in the datatypes section (http://www.postgresql.org/docs/7.4/interactive/datatype-datetime.html#DATAT YPE-TIMEZONE-TABLE), i.e. PST, -8:00, -800, -8, uniform, u? Lynna -- Spider Silk Design - http://www.spidersilk.net 509 St Clair W Box 73576, Toronto ON Canada M6C 1C0 Tel 416.651.2899 - Toll Free 1.866.651.2899 - Cell 416.873.9289