This is probably a very basic question but after reading documentation I still can’t figure out how to do it…
I have two strings in Python that contain dates of unknown format. I don’t know what formats they are in, except I know that both are valid date-time expressions. For example, one of them might be in the ISO format and the other in some other format.
All I need is to be able to compare the dates. What’s the correct way to turn strings into appropriate date-time objects so that they can be compared?
thanks!
The dateutil module has a date parser which can parse date strings in many formats.
For example,
Note that some datetime strings can be ambiguous:
10-09-2003could mean October 9 or September 10, for example.dateutilhas parameters likedayfirstandyearfirstto handle this: