Home > Enterprise >  Failed to conver string to timestamp bigQuery
Failed to conver string to timestamp bigQuery

Time:11-20

I am trying to convert string to timestamp but haven't been successful.

My field (payment_at) string contains

01-10-2021 9:04:06
01-10-2021 11:48:19
01-10-2021 16:01:35

I tried convert using

PARSE_TIMESTAMP("%Y-%m-%d %H:%M", payment_at)

and

CAST(payment_at AS TIMESTAMP)

but it shows error

Error running query; Invalid timestamp

Please help if I am doing anything wrong

Thankyou!

CodePudding user response:

Try this one:

SELECT PARSE_TIMESTAMP("%d-%m-%Y %H:%M:%S", "01-10-2021 11:48:19")

Documentation

CodePudding user response:

The format_string your provided does not match the timestamp string input. Replace "%Y-%m-%d %H:%M" with "%d-%m-%Y %H:%M:%S"

Documentation for the parse_timestamp function: https://cloud.google.com/bigquery/docs/reference/standard-sql/timestamp_functions#parse_timestamp

Documentation for supported format elements: https://cloud.google.com/bigquery/docs/reference/standard-sql/timestamp_functions#supported_format_elements_for_timestamp

  • Related