简体   繁体   中英

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 ?

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 在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM