Home > Archive > PostgreSQL Discussion > March 2006 > converting timstamptz to local time zone









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author converting timstamptz to local time zone
Peter Nixonn

2006-03-30, 7:30 am

How can I "select ('2006-01-01 9:00:00+02' at time zone 'GMT')::timestamp;"
where instead of GMT it has the local time zone of the machine I am running
it on (which varies between my machines)?
I dont want to hard code the timezone of the machine into the query.. I want
to pick it up from the environment, but cant figure out how :-(

--

Peter Nixon
http://www.peternixon.net/
PGP Key: http://www.peternixon.net/public.asc


---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

http://archives.postgresql.org

Martijn van Oosterhout

2006-03-30, 7:30 am

On Thu, Mar 30, 2006 at 02:24:55PM +0300, Peter Nixonn wrote:
> How can I "select ('2006-01-01 9:00:00+02' at time zone 'GMT')::timestamp;"
> where instead of GMT it has the local time zone of the machine I am running
> it on (which varies between my machines)?
> I dont want to hard code the timezone of the machine into the query.. I want
> to pick it up from the environment, but cant figure out how :-(


Just cast it to 'timestamp', that uses the configured timezone:

test=# set timezone='Europe/Amsterdam';
SET
test=# select '2006-01-01 9:00:00+02'::timesta
mptz::timestamp;
timestamp
---------------------
2006-01-01 08:00:00
(1 row)

test=# set timezone='Australia/Sydney';
SET
test=# select '2006-01-01 9:00:00+02'::timesta
mptz::timestamp;
timestamp
---------------------
2006-01-01 18:00:00
(1 row)

Have a nice day,
--
Martijn van Oosterhout <kleptog@svana.org> http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.


Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com