Age Calculation Based on Birthdate

  • Share this:

Code introduction


Calculates age based on the birthdate


Technology Stack : datetime, json

Code Type : Function

Code Difficulty : Intermediate


                
                    
import datetime
import json

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