Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

sql

postgresql

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?

like image 501
deadpool Avatar asked Dec 25 '22 00:12

deadpool


1 Answers

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');
like image 198
Vesa Karjalainen Avatar answered Jan 13 '23 13:01

Vesa Karjalainen