Skip to content

Instantly share code, notes, and snippets.

@doismellburning
Created February 21, 2012 16:13
Show Gist options
  • Save doismellburning/1877208 to your computer and use it in GitHub Desktop.
Save doismellburning/1877208 to your computer and use it in GitHub Desktop.
Determine age from a date of birth
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