Find number of months between two Dates in Ruby on Rails

phoenixwizard picture phoenixwizard · Feb 24, 2012 · Viewed 43.9k times · Source

I have two Ruby on Rails DateTime objects. How to find the number of months between them? (Keeping in mind they might belong to different years)

Answer

Massimiliano Peluso picture Massimiliano Peluso · Feb 24, 2012
(date2.year * 12 + date2.month) - (date1.year * 12 + date1.month)

more info at http://www.ruby-forum.com/topic/72120