Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Amazon Athena convert string to date time

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.

like image 684
Coopernicus Avatar asked Dec 05 '25 09:12

Coopernicus


1 Answers

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')
like image 98
Guru Stron Avatar answered Dec 07 '25 10:12

Guru Stron



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!