Convert date to unix timestamp in postgresql

date, postgresql, unix-timestamp

Solution

Try this

WHERE abc > extract(epoch from timestamp '2014-01-28 00:00:00')

PostgreSQL Docs

Problem

I have a table with a column abc carrying the unix timestamp (eg. 13898161481435) and I want to run a between dates select. It would be not efficient to do a ``` where TO_CHAR(TO_TIMESTAMP(abc / 1000), 'DD/MM/YYYY') > '14/01/2014 00:00:00' and ..; ``` which would convert every record. Rather do something like where abc > ('14/01/2014 00:00:00' tobigint()) and abc < ... But I cant find any reference, though for the reverse case.

Original source