Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine if one date is before another

Tags:

python

I have a date in the format "2011-06-24", and a list of other date strings in the same format. For each string in the list, I want to determine if that date is in the past, compared to "2011-06-24". Is there a way to do this easily in python?

like image 967
coffee Avatar asked Jun 24 '11 14:06

coffee


2 Answers

>>> "2011-06-24" > "2010-06-23"
True

>>> "2011-06-24" > "2012-06-25"
False
like image 130
Paolo Moretti Avatar answered Oct 16 '22 00:10

Paolo Moretti


What is the problem here? Since the dates are obviously in ISO notation you can perform a standard comparison of the dates as strings here...

like image 29
Andreas Jung Avatar answered Oct 16 '22 01:10

Andreas Jung