i too don't know i too don't know - 1 month ago 15
SQL Question

How to convert a timestamp to an integer (Unix epoch) in Postgres

I have a string

"2016-10-25T00:14:30.000"
in PostgreSQL.

I want to convert the timestamp to an integer, e.g: 1477354441

And I want to add custom minutes to that value, e.g.
1477354441+544(minutes) = 1477387081


How to achieve this in PostgreSQL?

Answer
SELECT EXTRACT(EPOCH FROM TIMESTAMP '2016-10-25T00:14:30.000');

SELECT EXTRACT(EPOCH FROM TIMESTAMP '2016-10-25T00:14:30.000' + INTERVAL '544 min');
Comments