How to calculate age in days in Python

2 Answers

0 votes
from datetime import date

today = date.today()

birthday = date(1966, 2, 27)

age = today - birthday

print(age.days)
 
    
    
    
'''
run:
    
20812
  
'''

 



answered Feb 20, 2023 by avibootz
0 votes
from datetime import date

def calculate_age(born):
    today = date.today()
    birthday = born
    
    return (today - birthday).days


print(calculate_age(date(1966, 2, 27)))
 
    
    
    
'''
run:
    
20812
  
'''

 



answered Feb 20, 2023 by avibootz
...