Is there a more efficient way of doing this below? I want to have the difference in years between two dates as a single scalar. Any suggestions are welcome.
Here's a spin off of what Kostyantyn posted in his "age2" function. It's slightly shorter/cleaner and uses the traditional/colloquial meaning of an "age" or difference in years as well:
def ageInYears( d ):
today = datetime.date.today()
currentYrAnniversary = datetime.date( today.year, d.month, d.day )
return (today.year - d.year) - (1 if today < currentYrAnniversary else 0)