Reputation: 33
I have extracted strings from a JSON field in the following format"2020-07-0217:39:02-04:00"
stored in a column called time_string
.
When I use the following function PARSE_TIMESTAMP("%Y-%m-%d%H:%M:%S%Ez", time_string)
I'm getting a "Failed to parse input string" error for all rows.
If I directly paste a date from time_string
as the input for the parse function, I'm getting an output.
Query: SELECT PARSE_TIMESTAMP("%Y-%m-%d%H:%M:%S%Ez", "2020-07-0217:39:02-04:00")
Output: 2020-07-02 21:39:02 UTC
I know there are multiple posts with similar issues here. Read through them but was unable to figure this one out.
Upvotes: 2
Views: 5537
Reputation: 173190
The only explanation I see is - some of your time_string
s have different format than you expects
To find the, run below
#standardSQL
select time_string
from `project.dataset.table`
where SAFE.PARSE_TIMESTAMP("%Y-%m-%d%H:%M:%S%Ez", time_string) is null
Update
Looks like some of your values wrapped with quotes
so use below instead
select PARSE_TIMESTAMP("%Y-%m-%d%H:%M:%S%Ez", trim(time_string, '"'))
Upvotes: 3