BigQuery:从带时区的日期时间中提取日期 [英] BigQuery: extract date from datetime with timezone

查看:21
本文介绍了BigQuery:从带时区的日期时间中提取日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在 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'

我怎么去这里?

非常感谢,珍妮

推荐答案

以下为 BigQuery Standard 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'

您可以通过在下面运行来进行快速测试

You can do quick test by running below

#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:从带时区的日期时间中提取日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆