Reputation: 11
I'm using a Postgresql database. The date field only shows values similar to 1,539,352,380.
What is this format and how would I convert it to regular mm/dd/yyyy?
Upvotes: 0
Views: 37
Reputation: 222482
This number looks like an epoch timestamp, that is the number of seconds since January 1st, 1970.
In Postgres, you can turn it to a timestamp with to_timestamp()
:
select to_timestamp(1539352380::bigint)
Or you can use explicit date arithmetics:
select date '1970-01-01' + 1539352380 * interval '1 second'
This gives 2018-10-12 13:53:00
. That is a timestamp
datatype. If you want to format it to a given string format, use to_char()
:
select to_char(to_timestamp(1539352380::bigint), 'mm/dd/yyyy')
Upvotes: 3