Presto SQL - Converting a date string to date format?

Viewed 136

I'm on presto and have a date formatted as varchar that looks like

"2022-03-01T09:24:58+09:00"

and I tried

 date_parse(filename,  '%Y-%m-%d %T+09:00')
 date_parse(ts,  '%Y-%m-%d %H:%i:%s')`

and give me an error

Invalid format: "2022-03-01T09:24:58+09:00" is malformed at "T09:24:58+09:00"

How do I convert this?

1 Answers
--- Given dates like 2022-03-01T09:24:58+09:00

SELECT with_timezone(
           date_parse(substr(dates, 1, 19),
                      '%Y-%m-%dT%H:%i:%s')
           substr(dates, 20)
       )
...

-- Output:
                         _col0
2022-03-01 09:24:58.000 +09:00
Related