Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

INVALID_CAST_ARGUMENT: Value cannot be cast to date

I have column in Athena table as time -> string

I am trying to convert to datetime as below :

SELECT
     "source"
   , "account"
   , CAST(time as date) Datetime
   
   FROM
     "testdata"

It gives me below error:

INVALID_CAST_ARGUMENT: Value cannot be cast to date: 2021-11-28T08:04:21Z
like image 745
Bokambo Avatar asked Sep 16 '25 18:09

Bokambo


1 Answers

Your timestamp looks like it's formatted using ISO 8601, and Athena has a function for that: from_iso8601_timestamp

SELECT
  source,
  account,
  from_iso8601_timestamp("time") AS datetime
FROM testdata

If you only want the date part you can cast the result of the function to date:

SELECT
  source,
  account,
  CAST(from_iso8601_timestamp("time") AS DATE) AS "date"
FROM testdata
like image 75
Theo Avatar answered Sep 23 '25 20:09

Theo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!