简体   繁体   English

BIGQUERY 中的字符串到日期

[英]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。

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.

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