Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Convert a postgres timestamp with no timezone column to a date

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

>Solution :

Does this work for you?

select "columnWithoutTimeZone"::date from my_table
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading