Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

CAST function

Hello All,
 
I am wondering if something changed with the format clause for the CAST function in BQ as I have run the following statement in the past and it worked.  Now I get this error: 
Failed to parse input timestamp string at 5 with format element 'MM'
 
SELECT
CAST(col AS DATE FORMAT 'YYYY.MM.DD') AS alias1,
DATE_DIFF(CURRENT_DATE(), CAST(col AS DATE FORMAT 'YYYY.MM.DD'),DAY) AS alias2
FROM `table`
 
Thanks in advance
Solved Solved
0 8 960
1 ACCEPTED SOLUTION

Nothing has changed for the CAST function syntax. The month portion of your date string is probably empty or exceeds 2 characters.

Better use SAFE_CAST if this is just a minor case in your data source.

View solution in original post

8 REPLIES 8