from datetime import date
def calculate_age(born):
today = date.today()
return today.year - born.year - ((today.month, today.day) < (born.month, born.day))
today_date = datetime.datetime.now()
dob = datetime.datetime(1982, 5, 20)
print(today_date - dob)
#Python Calculate Age from date of birth:
from datetime import date
def calculate_age(born):
today = date.today()
return today.year - born.year - ((today.month, today.day) < (born.month, born.day))
SELECT DATEDIFF (
year, DOB, getdate()) + CASE
WHEN (DATEADD(year,DATEDIFF(year, DOB, getdate()) , DOB) > getdate())
THEN - 1
ELSE 0
END
)
SELECT CASE WHEN dateadd(year, datediff (year, DOB, getdate()), DOB) > getdate()
THEN datediff(year, DOB, getdate()) - 1
ELSE datediff(year, DOB, getdate())
END as Age
FROM <table>