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?
>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
