How to do date comparison
How can I com开发者_Go百科pare two dates in python to determine if the second one is after the first one?
Hint: datetime.strptime()
def dateAfter(d1, d2):
from datetime import date
d1list = d1.split(".")
day1 = int(d1list[0])
month1 = int(d1list[1])
year1 = int(d1list[2])
d2list = d2.split(".")
day2 = int(d2list[0])
month2 = int(d2list[1])
year2 = int(d2list[2])
date1 = date(year1, month1, day1)
date2 = date(year2, month2, day2)
return date1 > date2
>>> dateAfter("13.12.2010", "08.12.2010")
True
精彩评论