Home > Back-end >  Amazon Athena convert string to date time
Amazon Athena convert string to date time

Time:12-09

I have a string in the following format dd-mmm-yyyy hh:mm, eg 23-Oct-2020 20:23, which I wish to convert to a datetime. I've tried:

parse_datetime(string, '%D-%M-%Y %H:%M')

but I'm hitting am error:

'INVALID_FUNCTION_ARGUMENT: Invalid format. Can anyone lend a helping hand please? Thanks.

CodePudding user response:

parse_datetime uses Java datetime formats. You can try:

select parse_datetime('23-Oct-2020 20:23', 'dd-MMM-yyyy HH:mm')

Output:

_col0
2020-10-23 20:23:00.000 UTC

Or use MySQL format with date_parse:

select date_parse('23-Oct-2020 20:24', '%d-%b-%Y %H:%i')
  • Related