You can download this code by clicking the button below.
This code is now available for download.
Calculates and returns the age based on the given birth date.
Technology Stack : datetime
Code Type : Function
Code Difficulty : Intermediate
import datetime
def calculate_age(birth_date):
today = datetime.date.today()
return today.year - birth_date.year - ((today.month, today.day) < (birth_date.month, birth_date.day))