27 Sep 19 · npack · #Bigquery ·   Bookmark   ×

Cast as Date / PARSE_DATE syntax in Google Bigquery

Use the PARSE_DATE function to convert a sting to a date in Bigquery:

SELECT PARSE_DATE("%Y%m%d", "20190927") as parsed_date;
SELECT PARSE_DATE("%Y%m%d", Column_Name) as parsed_column;

Format options:

  • %Y - The year with century as a decimal number. eg: 2019
  • %y - The year without century as a decimal number (00-99)
  • %m - The month as a decimal number (01-12)
  • %d - The day of the month as a decimal number (01-31)

Alternatively you can use the template formats:

  • %F - The date in the format %Y-%m-%d
  • %x - The date representation in MM/DD/YY format

Read more on the available formats here

npack

posted on 27 Sep 19

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

Copied