Retro Invaders
Retro Invaders

Reputation: 13

Bigquery cannot parse date from datetime

Bigquery cannot parse datetime from a date in spite of providing right format. Dates in my column are of the same format I used in the string:

SELECT EXTRACT(DATE FROM PARSE_TIMESTAMP('%Y-%m-%dT%H:%M:%S%z',"2021-03-22T14:00:00-03:00"))

This gives this error:

Failed to parse input string "2021-03-22T14:00:00-03:00"

I am trying to make this work by this answer

Upvotes: 1

Views: 1133

Answers (1)

Mikhail Berlyant
Mikhail Berlyant

Reputation: 172993

You should use %Ez instead of %z as in below

SELECT EXTRACT(DATE FROM PARSE_TIMESTAMP('%Y-%m-%dT%H:%M:%S%Ez',"2021-03-22T14:00:00-03:00"))       

See Supported format elements for TIMESTAMP for more details

Upvotes: 1

Related Questions