programming-examples/python/Date/Calculate an age in year.py

9 lines
283 B
Python
Raw Normal View History

2019-11-15 12:59:38 +01:00
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()