How to evaluate a date difference in years, months and days (ruby)?

This is an example for difference in days, hours, seconds. Add the fields that you need.

def calculate_difference
  minutes = (Date.parse("2009-06-20") - Date.today).to_i / 60
  days = minutes / (24*60)
  minutes -= days * 24*60
  hours = minutes / 60
  minutes -= hours * 60
  "#{days}d#{hours}h#{minutes}m"
end

You may be looking for distance_of_times_in_words


There is a RubyGem which returns Time difference in a hash like {:year => 0, :month => 0,...}

The link is : https://rubygems.org/gems/time_diff


Found the answer here:

More precise distance_of_time_in_words

with this gem:

https://github.com/radar/dotiw