问题
Can not find any solution to this:
Need to convert date(int) in the format - 20190101 to DATE in the format "2019-01-01"
I have tried:
- Cast(cast(20190101 AS STRING) AS date)
- FORMAT_DATE("%F",CAST(20190101 AS STRING))
- And so on...no success
回答1:
You are looking for PARSE_DATE()
:
select PARSE_DATE('%Y%m%d', CAST(20190101 AS STRING))
回答2:
Below is for BigQuery Standard SQL
#standardSQL
SELECT PARSE_DATE('%Y%m%d', CAST(20190101 AS STRING))
来源:https://stackoverflow.com/questions/54791436/big-query-convert-int-to-date