How to determine if one date was before another

I have a date in the format "2011-06-24" and a list of other date strings in the same format. For each row in the list, I want to determine whether this date was in the past, compared to "2011-06-24". Is there a way to make this easy in python?

+5
source share
3 answers

What is the problem? Since dates are obviously indicated by ISO, you can do a standard comparison of dates as strings here ...

+11
source
>>> "2011-06-24" > "2010-06-23"
True

>>> "2011-06-24" > "2012-06-25"
False
+22
source

Yes, see datetime comparison in python docs:

+5
source

All Articles