String to Date in Bigquery

String to Date in Bigquery

I am struggling trying to do this with Google BigQuery:

I do have a column with dates in this following STRING format:

6/9/2017   (M/D/YYYY)

I am wondering how can I deal with this, trying to use then the DATE clause., in order to get the DATE format:

YYYY-MM-DD.

Thanks in advance.

2 Answers

Easy one, with standard SQL:

#standardSQL
SELECT PARSE_DATE('%m/%d/%Y',  '6/22/2017')


2017-06-22  

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
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Marcus Vance
Author

Marcus Vance

Marcus Vance is a cybersecurity auditor and technology writer dedicated to educating the public about online safety, data privacy regulations, enterprise security, and emerging cyber threats.