24

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

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
Data_101
  • 893
  • 7
  • 14
  • 25
  • 3
    Have you looked into the [`date_parse`](https://prestodb.io/docs/0.172/functions/datetime.html) function? For example, try something like: `SELECT date_parse(d, '%b-%d-%Y')` – pault Feb 20 '18 at 19:16

2 Answers2

42

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

eshirvana
  • 23,227
  • 3
  • 22
  • 38
Blu3
  • 606
  • 1
  • 8
  • 11
6

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

Janne Annala
  • 25,928
  • 8
  • 31
  • 41
mohd Bilal
  • 61
  • 1
  • 4