[ create a new paste ] login | about

Link: http://codepad.org/gFx7lrmH    [ raw code | output | fork ]

Python, pasted on Jan 21:
1
2
3
4
5
6
7
8
9
10
import datetime
def calculate_age(dob):
    today = datetime.date.today()
    if today > dob:
        return today.year - dob.year - 1
    else:
        return today.year - dob.year    
        
print calculate_age( datetime.date(1982, 9, 29)) # outputs 31
print calculate_age( datetime.date(1992, 2, 29)) # outputs 21


Output:
1
2
31
21


Create a new paste based on this one


Comments: