Data_101
Data_101

Reputation: 953

Amazon Athena Convert String to Date

I am looking to convert the following string: mmm-dd-yyyy to a date: yyyy-mm-dd

e.g

Nov-06-2015 to 2015-11-06

within Amazon Athena

Upvotes: 29

Views: 153335

Answers (2)

mohd Bilal
mohd Bilal

Reputation: 81

You can also use cast function to get desire output as date type.

select cast(date_parse('Nov-06-2015','%M-%d-%Y') as date);

output--2015-11-06

in amazon athena https://prestodb.io/docs/current/functions/datetime.html used date parse to parse string and cast to convert 2015-11-06 00:00:00.000 into 2015-11-06

Upvotes: 8

Blu3
Blu3

Reputation: 676

I would do date_parse. Adjust your regex accordingly.

select date_parse('Nov-06-2015','%b-%d-%Y')

2015-11-06 00:00:00.000

refd:https://prestodb.io/docs/current/functions/datetime.html

Upvotes: 46

Related Questions