up vote 0 down vote favorite
share [g+] share [fb]

Basically I am trying to convert a date field from my database into a number of seconds old. I used UNIX_TIMESTAMP on our old MySQL database and am looking for an equivalent function in PostgreSQL.

Thanks in advance

link|improve this question

feedback

2 Answers

up vote 4 down vote accepted
SELECT extract(epoch FROM your_datetime_column)
FROM your_table

More details in the manual:

http://www.postgresql.org/docs/current/static/functions-datetime.html#FUNCTIONS-DATETIME-EXTRACT

link|improve this answer
feedback

This:

select CURRENT_TIMESTAMP - '1970-01-01';

Will give you an interval type. You can get seconds out of that interval result if you need it.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.