Skip to content

Instantly share code, notes, and snippets.

@sheldonh
Created March 2, 2015 12:23
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 sheldonh/4af05e4690bb7a7d78be to your computer and use it in GitHub Desktop.
Save sheldonh/4af05e4690bb7a7d78be to your computer and use it in GitHub Desktop.
age_at.rb
#!/usr/bin/env ruby
#
# Taken from http://stackoverflow.com/questions/819263/2357790#2357790
def age_at(dob, date)
date.year - dob.year - ((date.month > dob.month || (date.month == dob.month && date.day >= dob.day)) ? 0 : 1)
end
require "date"
puts age_at(Date.parse("1974-10-18"), Date.parse(ARGV[0]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment