I have following date:
2005-08-11T16:34:33Z
I need to know if this is date is before or after datetime(2009,04,01) and I can't seem to find a method that will convert that string to something that lets me compare it to datetime(2009,04,01) in a meaningful way.
Best Answer
Since the string is in ISO format, it can be meaningfully compared directly with the ISO format version of the
datetime
you mention:as you see, while you can't compare string with datetime objects, as long as the strings are in ISO format it's fine to compare them with the
.isoformat()
of the datetime objects. That's the beauty of the ISO format string representation of dates and times: it's correctly comparable and sorts correctly as strings, without necessarily requiring conversion into other types.If you're keen to convert, of course, you can: