Cast String into Date in BIGQUERY When Date is in the following format: M/D/YYYY

岁酱吖の 提交于 2021-02-10 18:15:27

问题


I have a string that is a date and it is in M/D/YYYY ie:

1/1/2018
12/31/2018

I get an invalid date error ( it shows: '2/18/2018' as the invalid date)

Any ideas?


回答1:


Below is example for BigQuery Standard SQL

#standardSQL
WITH `project.dataset.table` AS (
  SELECT '1/1/2018' date_as_string UNION ALL
  SELECT '12/31/2018'
)
SELECT PARSE_DATE('%m/%d/%Y', date_as_string) date_as_date
FROM `project.dataset.table`

with output:

Row date_as_date     
1   2018-01-01   
2   2018-12-31   


来源:https://stackoverflow.com/questions/49074680/cast-string-into-date-in-bigquery-when-date-is-in-the-following-format-m-d-yyyy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!