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

Extract hour from timestamp in string format on bigQuery

I have a timestamp that is in the string format that looks like 2010-02-02T07:54:40Z. How can I get the HOUR from this timestamp?

I tried SELECT dt, EXTRACT(HOUR FROM dt) FROM table but I am getting this error:

No matching signature for function EXTRACT for argument types: DATE_TIME_PART FROM STRING. Supported signatures: EXTRACT(DATE_TIME_PART FROM DATE); EXTRACT(DATE_TIME_PART FROM TIMESTAMP [AT TIME ZONE STRING]); EXTRACT(DATE_TIME_PART FROM DATETIME); EXTRACT(DATE_TIME_PART FROM TIME); EXTRACT(DATE_TIME_PART FROM INTERVAL) 

How do I get the HOUR from 2010-02-02T07:54:40Z?

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

>Solution :

First you need to cast string as timestamp and then need to extract hour.
I have replicated issue in my project and here is the solution.

Query part- ( ts_string is column name with string datatype)
EXTRACT(hour
FROM
CAST(ts_string AS timestamp)) AS hour_extracted
enter image description here

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