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

前端 未结 2 1048
执笔经年
执笔经年 2020-12-29 19:22

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

相关标签:
2条回答
  • 2020-12-29 19:58

    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;

    0 讨论(0)
  • 2020-12-29 20:01

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

    select extract(epoch from ts) from data
    
    0 讨论(0)
提交回复
热议问题