Age Calculation from Birthdate

  • Share this:

Code introduction


Calculate the age given a birthdate.


Technology Stack : datetime, math, os, re, sys

Code Type : Function

Code Difficulty : Intermediate


                
                    
import datetime
import math
import os
import re
import sys

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