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

How to convert text to timestamp with adjusted format?

I have a table that one of its column contains timestamp.

This column defined as text field.

The timestamp format is as follow:

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

"2021-01-05T:12:29:30"
"2021-05-15T:15:23:00"

How can I convert this text field to timestamp using TO_TIMESTAMP function ?

>Solution :

You can use TO_TIMESTAMP with a format

to_timestamp(you_text_column,'YYYY-MM-DDT:hh24:mi:ss') as your_timestamp

But somehow that odd format you have can also be type casted to a timestamp

select '2021-01-05T:12:29:30'::timestamp

I’m calling it odd because it’s not even in an ISO 8601 format.
Since it has that extra :

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