Thursday, February 25, 2010

Convert unix timestamp to PostgreSQL timestamp

SELECT
                TIMESTAMP 'epoch' + 1195374767 * INTERVAL '1 second'


To convert back to unix timestamp you can use date_part:

SELECT
                date_part('epoch',CURRENT_TIMESTAMP)::int 


Ref : http://www.postgresonline.com/journal/index.php?/archives/3-Converting-from-Unix-Timestamp-to-PostgreSQL-Timestamp-or-Date.html

No comments:

Post a Comment