23

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 1

43

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
Sign up to request clarification or add additional context in comments.

2 Comments

Then use to_char if you want to output a specific date/time/timestamp format.
@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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.