Skip to content
Advertisement

Change ‘1 Apr 2022, noon’ to datetime format python

I want to change ‘1 Apr 2022, noon’ to YYYY-MM-DD HH:MM:SS format.

I know the datetime thing in python has the ability to parse but I am unsure how

Advertisement

Answer

You can use the dateparser module’s parse() function:

JavaScript

This gets us a datetime.datetime object. We can now call strftime() to format it properly:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement