Search code examples
sqlpostgresqlunix-timestamp

Converting a timestamp to a unix_timestamp in Postgres


I need to convert a timestamp to a unix_timestamp in Postgres.

The timestamp being in the following format: 2019-05-09 11:40:01

Thanks


Solution

  • Use extract(epoch from . . . ):

    select extract(epoch from '2019-05-09 11:40:01'::timestamp)