How to convert date time into unix epoch value in Postgres?

Ashish Kumar Saxena picture Ashish Kumar Saxena · Jan 2, 2015 · Viewed 34.1k times · Source

How do I convert the following format to UNIX timestamps?

A value like: 01-02-2015 10:20 PM should be converted to: 1418273999000

I did try to_timestamp function but its not working for me.

Answer

Joe Love picture Joe Love · Jan 2, 2015

If your data is stored in a column called ts, in a table called data, do this:

select extract(epoch from ts) from data