Home > Software design >  Transform Timestamp Without Time Zone to a simple date in PostgreSQL
Transform Timestamp Without Time Zone to a simple date in PostgreSQL

Time:07-30

Suppose I have a column that has the datatype Timestamp without Time Zone and looks like this:

Sun Jan 01 1933 00:00:00 GMT 0000 (Coordinated Universal Time)

I want to change it to a simple date like this 01/01/1933. I have tried the following, but there is no change in the output:

SELECT timestamp_date::date as new_date,
       DATE(timestamp_date) as also_date
FROM my_schema.my_table;

What am I doing wrong here?

CodePudding user response:

you can use the function to_char

to_char(timestamp_date, 'DD/MM/YYYY');

Or you can play with DATESTYLE configuration parameters, but use to_char always as possible, to avoid the change of configuration

  • Related