28 Mar 19 · Mike-Barn · #bigquery ·   Bookmark   ×

How to convert string column to Timestamp in BigQuery ?

To convert string to timestamp, you will need to use the Parse_Timestamp() function in Bigquery. 

For example: If you have to convert the string "20171208 500" to timestamp, which is of the YYYYMMDD HMM, use the below syntax:

PARSE_TIMESTAMP("%Y%m%d%k%M", utc_timestamp)

If you use a wrong pattern, it will throw the below error message:

Invalid timestamp: '20171208 500'

More examples:

SELECT PARSE_TIMESTAMP("%a %b %e %I:%M:%S %Y", "Thu Dec 25 07:30:00 2008")
SELECT PARSE_TIMESTAMP("%c", "Thu Dec 25 07:30:00 2008")


posted on 28 Mar 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