Re: Function to convert from (integer) UNIXTIME to DATETIME

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Function to convert from (integer) UNIXTIME to DATETIME
Дата
Msg-id 19392.962057402@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Function to convert from (integer) UNIXTIME to DATETIME  ("Morten W. Petersen" <morten@src.no>)
Список pgsql-general
"Morten W. Petersen" <morten@src.no> writes:
> Is there such a function (couldn't find it)

You can cast an integer representing Unix timestamp directly to abstime,
and thence to any other datetime type you want:

regression=# select abstime(962057134);
        abstime
------------------------
 2000-06-26 18:05:34-04
(1 row)

To go the other way, you can cast to abstime and then int4, or you can
use date_part('epoch',...):

regression=# select int4(abstime('2000-06-26 18:05:34-04'::timestamp));
   int4
-----------
 962057134
(1 row)

regression=# select date_part('epoch','2000-06-26 18:05:34-04'::timestamp);
 date_part
-----------
 962057134
(1 row)

This works in 7.0, not sure about earlier releases.

            regards, tom lane

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

Предыдущее
От: Joseph Shraibman
Дата:
Сообщение: Re: DateTime fields
Следующее
От: "Len Morgan"
Дата:
Сообщение: Re: Conversion from MS Access to Postgresql