programming-examples/python/Date/Calculate an age in year.py
2019-11-15 12:59:38 +01:00

9 lines
283 B
Python

from datetime import date
def calculate_age(dtob):
today = date.today()
return today.year - dtob.year - ((today.month, today.day) < (dtob.month, dtob.day))
print()
print(calculate_age(date(2006,10,12)))
print(calculate_age(date(1989,1,12)))
print()