[英]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
.我有一个字符串格式的时间戳,看起来像2010-02-02T07:54:40Z
。 How can I get the HOUR
from this timestamp?我怎样才能从这个时间戳中得到HOUR
数?
I tried SELECT dt, EXTRACT(HOUR FROM dt) FROM table
but I am getting this error:我尝试SELECT dt, EXTRACT(HOUR FROM dt) FROM table
但我收到此错误:
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
?如何从2010-02-02T07:54:40Z
获取HOUR
?
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查询部分-(ts_string 是字符串数据类型的列名)EXTRACT(hour FROM CAST(ts_string AS timestamp)) AS hour_extracted
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.