gwydion93
gwydion93

Reputation: 1923

Transform Timestamp Without Time Zone to a simple date in PostgreSQL

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?

Upvotes: 1

Views: 10198

Answers (1)

Anthony Sotolongo
Anthony Sotolongo

Reputation: 1648

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

Upvotes: 3

Related Questions