Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if a date has Passed in Python (Simply)

Tags:

python

date

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

For example:- If the date is 01/05/2015, and the date; 30/04/2015 was in-putted into Python, it would return True, to say the date has passed.

This needs to be as simple and efficient as possible.

Thanks for any help.

like image 540
DibDibsTH13TEEN Avatar asked Apr 30 '15 18:04

DibDibsTH13TEEN


1 Answers

you may use datetime, first parse String to date, 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()
d2>d1
like image 91
Jose Ricardo Bustos M. Avatar answered Oct 24 '22 11:10

Jose Ricardo Bustos M.