0

"Date" data from GA in BQ is "yyyymmdd" which is not able to convert to "date" data set. Is there any way to make BQ recognize it as "date"?

Thank you,

1 Answer 1

0

According to the documentation, the date field is exported as String from your GA data.

However, it is possible to change that after you export your data to BigQuery. You can overwrite your current table or create a new one with the date format you desire. In order to achieve this, we will use PARSE_DATE() builtin method. It receives a String that will be casted to date according to the string format it has. Below is the StandardSQL syntax in BigQuery:

SELECT PARSE_DATE("%Y%m%d", date) as date FROM `project.dataset.table`

The date will be outputed as YYYY-MM-DD. In addition, if you want to change the date format, you can use FORMAT_DATE() builtin method using one of the formatting elements.

In your case that you want to replace the whole table with the date column with the desired format, you could use the following syntax:

CREATE OR REPLACE TABLE `project.dataset.table` AS 
( SELECT * REPLACE(PARSE_DATE("%Y%m%d",date) as date) FROM `project.dataset.table`)

Therefore, your table will have all the same columns, but the date field will be formatted as DATE.

1
  • @Yui001, please consider accepting and upvoting the answer. Jun 19, 2020 at 6:58

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.