def num_years(begin, end=None):
    if end is None:
        end = datetime.now()
num_years = int((end - begin).days / 365.25)
if begin > yearsago(num_years, end):
    return num_years - 1
else:
    return num_years
Python timedelta in years