Skip to content

Instantly share code, notes, and snippets.

@Ank13
Created February 16, 2014 13:39
Show Gist options
  • Save Ank13/9034360 to your computer and use it in GitHub Desktop.
Save Ank13/9034360 to your computer and use it in GitHub Desktop.
puts "What year were your born?"
birth_year = gets.chomp
puts "What month were your born?"
birth_month = gets.chomp
puts "What day were your born?"
birth_day = gets.chomp
seconds_diff = Time.now - Time.new(birth_year, birth_month, birth_day)
pretty_print_seconds = seconds_diff.round(0).to_s.reverse.gsub(/(\d{3})(?=\d)/, '\\1,').reverse
puts "You are #{pretty_print_seconds} seconds old."
years = seconds_diff / 60 / 60 / 24 / 365
puts "You are #{years.round(2)} years old."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment