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

别说谁变了你拦得住时间么 提交于 2019-11-29 10:50:49

问题


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.


回答1:


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

select extract(epoch from ts) from data



回答2:


To add Joe's answer, you can use date_part, i think it's syntax is clearer than 'extract'.

select date_part('epoch', ts) from data;



来源:https://stackoverflow.com/questions/27740363/how-to-convert-date-time-into-unix-epoch-value-in-postgres

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!