HybridFenix
HybridFenix

Reputation: 125

Standard SQL String to Date

I have a string date formatted as 20190101 that I'm trying to convert to 2019-01-01. How would I do this in standard? I know in legacy I could simply do date('20190101'), but not sure how to do this in standard.

Thank you

Upvotes: 0

Views: 167

Answers (2)

Gauravsa
Gauravsa

Reputation: 6524

Easy:

SELECT PARSE_DATE('%Y%m%d',  '20190101')

Format elements for date is here:

https://cloud.google.com/bigquery/docs/reference/standard-sql/functions-and-operators#supported-format-elements-for-date

Upvotes: 1

Gordon Linoff
Gordon Linoff

Reputation: 1269773

Use PARSE_DATE():

select PARSE_DATE('%Y%m%d', '20190101')

Upvotes: 3

Related Questions