Convert String to Date (MM-DD-YYYY) format in Athena (Glue Tables)

0

Using Glue Crawlers, I created Glue tables and querying it from Athena- How to I convert string to Date format? "2022-11-16T00:00:00.000Z"

I have tried to_date function!

質問済み 1年前7992ビュー
1回答
1
承認された回答

try date_parse or from_iso8601_date function.

select date_parse(substr('2022-11-16T00:00:00.000Z',1,10),'%Y-%m-%d')

--OR TRY BELOW
select from_iso8601_date(substr('2022-11-16T00:00:00.000Z',1,10))

For a full list of functions, please check the reference based on the Athena Engine version you are using https://docs.aws.amazon.com/athena/latest/ug/functions.html Reference: https://trino.io/docs/current/functions/datetime.html?highlight=date_parse#date_parse

profile pictureAWS
回答済み 1年前
profile picture
エキスパート
レビュー済み 1ヶ月前
  • Thanks for your response, it helps!! (I was trying to avoid substring function in the beginning)

    The above functions are helpful and I tried this as well and it worked- select date_parse(snapshot_date,'%Y-%m-%dT%H:%i:%s%.000Z') as date --> (This will convert to Date time (zone) format)

    select date_parse(substr('2022-11-16T00:00:00.000Z',1,10),'%Y-%m-%d') --> (This will convert to Date time format)

    select from_iso8601_date(substr('2022-11-16T00:00:00.000Z',1,10)) --> (This will convert to date format)

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン