Age from birthdate in python

That can be done much simpler considering that int(True) is 1 and int(False) is 0:

from datetime import date

def calculate_age(born):
    today = date.today()
    return today.year - born.year - ((today.month, today.day) < (born.month, born.day))

Leave a Comment