Created
March 2, 2015 12:23
-
-
Save sheldonh/4af05e4690bb7a7d78be to your computer and use it in GitHub Desktop.
age_at.rb
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
#!/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