Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # By Websten from forums
- #
- # Given your birthday and the current date, calculate your age in days.
- # Account for leap days.
- #
- # Assume that the birthday and current date are correct dates (and no
- # time travel).
- #
- def daysBetweenDates(year1, month1, day1, year2, month2, day2):
- yeardic = {"1True":31, "2True":29, "3True":31, "4True":30, "5True":31, "6True":30, "7True":31, "8True":31, "9True":30, "10True":31, "11True":30, "12True":31,"1False":31, "2False":28, "3False":31, "4False":30, "5False":31, "6False":30, "7False":31, "8False":31, "9False":30, "10False":31, "11False":30, "12False":31}
- totaldays = 0
- def isleapyear():
- if year1 % 400 == 0:
- return str(month1) + "True"
- elif year1 % 100 == 0:
- return str(month1) + "False"
- elif year1 % 4 == 0:
- return str(month1) + "True"
- else:
- return str(month1) + "False"
- totaldays += yeardic[str(isleapyear())] -day1
- month1 +=1
- if month1 == 13:
- month1 == 1
- year1 += 1
- while (month1,year1) != (month2,year2):
- totaldays += yeardic[str(isleapyear())]
- month1 +=1
- if month1 == 13:
- month1 = 1
- year1+=1
- totaldays += day2
- print totaldays
- return totaldays
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement