Skip to content

Instantly share code, notes, and snippets.

@cbeier
Created March 26, 2010 08:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cbeier/344692 to your computer and use it in GitHub Desktop.
Save cbeier/344692 to your computer and use it in GitHub Desktop.
calculate the exact age
def age(birthday)
y = Date.today.year - birthday.year
m = Date.today.month - birthday.month
d = Date.today.day - birthday.day
case
when m < 0
age = y-1
when m = 0
case
when d = 0
age = y
end
when m > 0
age = y
end
age
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment