In python, subtracting two datetime.date
objects results in a datetime.timedelta
object, which has a days
attribute.
Turning the number of days difference into years and months is not clearly defined; if you define a year as 365 days and a month as 30 days, you could use:
years, remainder = divmod(diff1.days, 365)
months = remainder // 30
Or, you could define average year and month lengths to be (slightly) more accurate:
avgyear = 365.2425 # pedants definition of a year length with leap years
avgmonth = 365.2425/12.0 # even leap years have 12 months
years, remainder = divmod(diff1.days, avgyear)
years, months = int(years), int(remainder // avgmonth)
With the latter calculation, your second difference comes out as 11 years and 3 months.