calculate the number of months difference between two dates

410 views
Skip to first unread message

Tom Mac

unread,
Jun 24, 2010, 8:29:48 AM6/24/10
to rubyonra...@googlegroups.com
Please share if there any such easy methods in rails. I have dates like

date1 = Date.today
date2 = Date.today - 3.months (Example can be anything)

Now how to get month difference as 3 (date1 - date2)

Thanks for any help
Tom
--
Posted via http://www.ruby-forum.com/.

Michael Pavling

unread,
Jun 24, 2010, 9:17:35 AM6/24/10
to rubyonra...@googlegroups.com
On 24 June 2010 13:29, Tom Mac <li...@ruby-forum.com> wrote:
>     Now how to get month difference as 3  (date1 - date2)

Googling for "ruby months between two dates" gleans this as the first result:
http://www.francisfish.com/getting_the_number_of_months_between_two_dates_in_rubyrails.htm

...and loads of other likely candidates.

Reply all
Reply to author
Forward
0 new messages