sqlgoogle-bigquerybigquery-udfspring-cloud-gcp-bigquery

Bigquery, converting uncommon STRING to TIMESTAMP


in bigquery i have STRING column which has value 2024/2/9 23:52:05 GMT+07:00, raw date without a leading zeros, sometimes i got 2024/12/10 20:51:05 GMT+07:00, is it possible to convert this column into a new timestamp column since i cannot using format timestamp with %Y-%m-%d %H:%M:%S %Z


Solution

  • i was able to resolve using this query CONCAT(SPLIT(SPLIT(datetime_cols, ' ')[0],'/')[0], '-' ,LPAD(SPLIT(SPLIT(datetime_cols, ' ')[0],'/')[1], 2, '0'), '-', LPAD(SPLIT(SPLIT(datetime_cols, ' ')[0],'/')[2], 2, '0'),' ', LPAD(SPLIT(SPLIT(datetime_cols, ' ')[1],':')[0], 2, '0'),':',LPAD(SPLIT(SPLIT(datetime_cols, ' ')[1],':')[1], 2, '0'),':',LPAD(SPLIT(SPLIT(datetime_cols, ' ')[1],':')[2], 2, '0'))