Re: converting timstamptz to local time zone

Поиск
Список
Период
Сортировка
От Martijn van Oosterhout
Тема Re: converting timstamptz to local time zone
Дата
Msg-id 20060330113807.GA16142@svana.org
обсуждение исходный текст
Ответ на converting timstamptz to local time zone  (Peter Nixonn <listuser@peternixon.net>)
Список pgsql-general
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'::timestamptz::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'::timestamptz::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.

Вложения

В списке pgsql-general по дате отправления:

Предыдущее
От: Tino Wildenhain
Дата:
Сообщение: Re: How to detect primary key of a table
Следующее
От: Michael Fuhr
Дата:
Сообщение: Re: How to detect primary key of a table