问题描述
我正在尝试在BigQuery中返回一列,其中包含从 start_time 列中提取的日期.
I am trying to return a column in BigQuery with the extracted date from the column start_time.
该列中的值的格式为:11/27/2019 14:40:15 CET +0100
The values in the column are of the format: 11/27/2019 14:40:15 CET +0100
我编写了以下代码:
SELECT EXTRACT(DATE FROM TIMESTAMP(start_time))
AS date
FROM `cc_raw.cc_exp`
但是我收到错误消息:无效的时间戳:'11/27/2019 14:40:15 CET +0100'
However I am getting the error message: Invalid timestamp: '11/27/2019 14:40:15 CET +0100'
我该怎么办?
非常感谢,珍妮(Janine)
Many thanks,Janine
推荐答案
以下是BigQuery标准SQL
Below is for BigQuery Standard SQL
#standardSQL
SELECT
EXTRACT(DATE FROM PARSE_TIMESTAMP('%m/%d/%Y %H:%M:%S %Z %z', start_time)) AS date
FROM `cc_raw.cc_exp`
您将 PARSE_TIMESTAMP
函数与'%m/%d/%Y%H:%M:%S%Z%z'
一起使用来处理以字符串形式显示的时间戳格式为 '11/27/2019 14:40:15 CET +0100'
You use PARSE_TIMESTAMP
function with '%m/%d/%Y %H:%M:%S %Z %z'
to handle timestamps presented as strings formatted as '11/27/2019 14:40:15 CET +0100'
您可以通过在下面运行
#standardSQL
SELECT
EXTRACT(DATE FROM PARSE_TIMESTAMP('%m/%d/%Y %H:%M:%S %Z %z', '11/27/2019 14:40:15 CET +0100')) AS date
这篇关于BigQuery:从带时区的datetime中提取日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!