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

\n\n

Solution

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

\n\n
#standardSQL\nWITH `project.dataset.table` AS (\n  SELECT '20180902' timeStamp   \n)\nSELECT \n  `timeStamp`, \n  PARSE_DATE('%Y%m%d', timeStamp    ) AS date    \nFROM `project.dataset.table`\n
\n\n

Result: 

\n\n
Row   timeStamp   date   \n1     20180902    2018-09-02     

victor

posted on

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