How to check if a date has passed in Python (simple)

I have looked to see if I can find a simple method in Python to see if a date has passed.

For example: - If the date 01/05/2015

and date; 30/04/2015

was placed in Python, it will return True to say the date has passed.

It should be as simple and efficient as possible.

Thanks for any help.


source to share

3 answers

you can use datetime, parse String to date first, then you can compare

import datetime
d1 = datetime.datetime.strptime('05/01/2015', "%d/%m/%Y").date()
d2 = datetime.datetime.strptime('30/04/2015', "%d/%m/%Y").date()




from datetime import datetime
present =
print datetime(2015,04,30) < present #should return true


Got stuff from this question / answer: How do I compare two dates?



Just compare them?

>>> t1 =
>>> t2 =
>>> t1>t2
>>> t1<t2




All Articles