Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert date from long time postgres

How do I select the date as a readable string from epoch time in milliseconds?

Some like: SELECT *, to_date(time_in_milli_sec) FROM mytable

like image 406
Nirmal- thInk beYond Avatar asked Oct 24 '11 08:10

Nirmal- thInk beYond


People also ask

How do I convert datetime to date in PostgreSQL?

The TO_DATE function in PostgreSQL is used to converting strings into dates. Its syntax is TO_DATE(text, text) and the return type is date. The TO_TIMESTAMP function converts string data into timestamps with timezone. Its syntax is to_timestamp(text, text) .

How do I change the date format in PostgreSQL?

You can change the format in the postgresql. conf file. The date/time styles can be selected by the user using the SET datestyle command, the DateStyle parameter in the postgresql. conf configuration file, or the PGDATESTYLE environment variable on the server or client.


1 Answers

Per PostgreSQL docs:

SELECT *, to_timestamp(time_in_milli_sec / 1000) FROM mytable 
like image 124
Yahia Avatar answered Sep 24 '22 00:09

Yahia