[英]STRING to DATE in BIGQUERY
I am struggling to try to do this with Google BigQuery:我正在努力尝试使用 Google BigQuery 来做到这一点:
I do have a column with dates in the following STRING format:我确实有一个包含以下 STRING 格式的日期的列:
6/9/2017 (M/D/YYYY)
I am wondering how can I deal with this, trying to use the DATE
clause in order to get the this format: YYYY-MM-DD.我想知道如何处理这个问题,尝试使用
DATE
子句来获得这种格式:YYYY-MM-DD。
Easy one, with standard SQL:简单的一个,使用标准 SQL:
#standardSQL
SELECT PARSE_DATE('%m/%d/%Y', '6/22/2017')
2017-06-22
https://cloud.google.com/bigquery/docs/reference/standard-sql/functions-and-operators#supported-format-elements-for-date https://cloud.google.com/bigquery/docs/reference/standard-sql/functions-and-operators#supported-format-elements-for-date
This solution can work这个解决方案可以工作
SELECT CAST(
CONCAT(
SUBSTR(DT_DOCUMENTO, 0 , 4),
'-' ,
SUBSTR(DT_DOCUMENTO, 5 , 2),
'-' ,
SUBSTR(DT_DOCUMENTO, 7 , 2)
) AS DATE
) AS FORMAT_DATE
If you are lazy you can do date parsing with automatic format detection如果你很懒,你可以通过自动格式检测来进行日期解析
select bigfunctions.eu.parse_date('1/20/21') as cleaned_date
will give会给
+--------------------+
| cleaned_date |
+--------------------+
| date('2021-01-20') |
+--------------------+
as well as也
select bigfunctions.eu.parse_date('Wed Jan 20 21:47:00 2021') as cleaned_date
https://unytics.io/bigfunctions/reference/#parse_date https://unytics.io/bigfunctions/reference/#parse_date
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.