Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have to make a simple difference between two dates:

Date.parse("2009-06-20") - Date.today

This gives me the difference of the dates in days.

Anyone know a way to easily convert that to the following format:

The event occurred X years, Y months and Z days ago

Thank you.

like image 543
robertokl Avatar asked Jun 21 '10 22:06

robertokl


2 Answers

Found the answer here:

More precise distance_of_time_in_words

with this gem:

https://github.com/radar/dotiw

like image 125
robertokl Avatar answered Oct 16 '22 00:10

robertokl


You may be looking for distance_of_times_in_words

like image 5
Chubas Avatar answered Oct 16 '22 00:10

Chubas