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

Cast string 'May 11 2022 9:16AM' to a timestamp

I have this query:

select to_timestamp('May 11 2022  9:16AM', 'Month DD YYYY HH:MI')

Returns: 2022-05-11 09:16:00.000 -0300

The expression 'Month DD YYYY HH:MI' is the result of some trial and error.

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 can’t tell if what I have is ‘right’? Expected something more like: 2022-05-11 09:16:00

What is ...00.000 -0300 this part?

How can I get a timestamp from May 11 2022 9:16AM?

>Solution :

Per the docs Data Type Formatting Functions to_timestamp:

to_timestamp ( text, text ) → timestamp with time zone

Converts string to time stamp according to the given format. (See also to_timestamp(double precision) in Table 9.32.)

to_timestamp(’05 Dec 2000′, ‘DD Mon YYYY’) → 2000-12-05 00:00:00-05

So what you are seeing is a timestamptz value, e.g a timestamp with time zone information. If you want to eliminate the time zone then:

select to_timestamp('May 11 2022  9:16AM', 'Month DD YYYY HH:MI')::timestamp;
    to_timestamp     
---------------------
 2022-05-11 09:16:00


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