Home > database >  Convert a postgres timestamp with no timezone column to a date
Convert a postgres timestamp with no timezone column to a date

Time:06-30

Given a postgres table with a column that is a timestamp without time zone

 select "columnWithoutTimeZone" from my_table

Which results in:

 columnWithoutTimeZone
 Jun 11, 2022, 1:15:06 AM
 Jun 11, 2022, 1:15:06 AM

How can the date component of timestamp be extracted?

I tried

select to_date("columnWithoutTimeZone") from my_table

But this produced an error:

ERROR: function to_date(timestamp without time zone) does not exist

There is a similar stack question, but that deals with timezone conversions. I am simply trying to extract the Jun 11, 2022 that is presently represented in the column.

Thank you in advance for your consideration and response.

CodePudding user response:

Does this work for you?

select "columnWithoutTimeZone"::date from my_table
  • Related