Tom
Tom

Reputation: 34356

BigQuery PARSE_TIMESTAMP with unix timestamp - Failed to parse input string

I have a table that looks like this

email created_date
[email protected] 1617753600000
[email protected] 1601510400000

bigquery tells me that created_date is stored a string. So I need to transform created_date from a unix timestamp into a date.

I'm curious why does PARSE_TIMESTAMP not work in this case? Isn't this how it should be used?

Upvotes: 0

Views: 911

Answers (2)

Gordon Linoff
Gordon Linoff

Reputation: 1269443

You have Unix epoch time represented in milliseconds rather than the more common seconds. I recommend using the timestamp_millis() function:

select timestamp_millis(cast(created_date as int64))

Note that there are also functions for timestamp_micros() and timestamp_seconds().

Upvotes: 2

Sergey Geron
Sergey Geron

Reputation: 10152

%s - stands for "The number of seconds since 1970-01-01 00:00:00 UTC", but looks like you've got microseconds instead. Try this: parse_timestamp("%s", left(created_date, 10))

Upvotes: 1

Related Questions