sql - Why is BigQuery converting some dates to timestamps but not others? -


our sql query shown below converting strings timestamp fields failing on dates , not on others. causing conversion fail?

select birthdate, timestamp(regexp_replace(birthdate, r'(..)/(..)/(....)', r'\3-\2-\1')) ts [our_project:our_table] limit 1000 

here results. notice bigquery giving "null" many of dates. why regex failing? there add make more robust?

sql results

here second conversion query tried.

select birthdate, timestamp(year + '-' + month + '-' + day) output_timestamp (   select      birthdate,      regexp_extract(birthdate, '.*/([0-9]{4})$') year,      regexp_extract(birthdate, '^([0-9]{2}).*') day,      regexp_extract(birthdate, '.*/([0-9]{2})/.*') month         [our_project:our_table] ) limit 1000 

notice nulls appeared in these results well.

sql_query2

how might fix going wrong?

it turns out month , day swapped (international versus u.s.) result ranges invalid timestamp. once swapped day , month - conversions occurred without problems.


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -