Created
February 21, 2012 16:13
-
-
Save doismellburning/1877208 to your computer and use it in GitHub Desktop.
Determine age from a date of birth
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import date | |
def determine_age(dob): | |
""" | |
Surprisingly nontrivial - I don't claim this function to be very correct... | |
""" | |
today = date.today() | |
age = today.year - dob.year | |
if today.month < dob.month: | |
age -= 1 | |
elif today.month == dob.month: | |
if today.day < dob.day: | |
age -= 1 | |
return age |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment