user12625679
user12625679

Reputation: 696

Converting string to timestamp issues sql

I'm trying to cast a string to timestamp but I'm getting the following error:

Failed to output to file. Query failed: Value cannot be cast to timestamp: 2020-03-23T05:17:44.000Z

I'm using the query below:

select CAST(purchase_date AS timestamp)
from main_table

Upvotes: 0

Views: 107

Answers (2)

Gordon Linoff
Gordon Linoff

Reputation: 1269543

Try parse_datetime():

select parse_datetime('2020-03-23T05:17:44.000Z', '%Y-%m-%dT%H:%i:%s.%fZ')

Upvotes: 0

ebyhr
ebyhr

Reputation: 1637

You can use from_iso8601_timestamp function if timestamp with time zone type is acceptable.

Or, you can use date_parse function.

Upvotes: 1

Related Questions