Say I have a column that contains unix timestamps - an int representing the number of seconds since the epoch. They look like this: 1347085827. How do I format this as a human-readable date string in my SELECT query?
1 Answer
Postgresql has a handy built-in function for this: to_timestamp(). Just wrap that function around the column you want:
Select a, b, to_timestamp(date_int) FROM t_tablename
2 Comments
Craig Ringer
Then use
to_char if you want to output a specific date/time/timestamp format.Vasilii Suricov
@CraigRinger yep, then read an article "how to convert timestamp to date"). The answer is nearly not correct. it should be
to_timestamp(date_int)::date to get 2022-05-26 from 1653592838 or TO_CHAR(to_timestamp(date_int), 'dd-mm-yyyy') for 26-05-2022