How to parse and convert string to date in Bigquery

The string value in this column looks like this "20180902". It needs to be converted to a date value in BigQuery

Solution

Below example shows that if value is really "20180902" as you state it should work

#standardSQL
WITH `project.dataset.table` AS (
  SELECT '20180902' timeStamp   
)
SELECT 
  `timeStamp`, 
  PARSE_DATE('%Y%m%d', timeStamp    ) AS date    
FROM `project.dataset.table`

Result: 

Row   timeStamp   date   
1     20180902    2018-09-02     

victor

posted on 01 Feb 21

Enjoy great content like this and a lot more !

Signup for a free account to write a post / comment / upvote posts. Its simple and takes less than 5 seconds