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?
Postgres DATE data type Postgres uses the DATE data type for storing different dates in YYYY-MM-DD format. It uses 4 bytes for storing a date value in a column. You can design a Postgres table with a DATE column and use the keyword DEFAULT CURRENT_DATE to use the current system date as the default value in this column.
Postgresql date to string yyymmdd In Postgresql, dates can be converted in specific string formats like yyymmdd, where yyyy for a year, mm for a month, and dd for the date. For that conversion, we will use the to_char function to format the date as a string. Syntax: TO_CHAR(date_value, string_format);
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With