Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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')
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading