# Calculate the number of months difference between two dates

**URL:** <https://www.ruby-forum.com/t/calculate-the-number-of-months-difference-between-two-dates/190647>\
**Category:** Rails\
**Created:** [June 24, 2010, 2:29pm UTC](https://www.ruby-forum.com/t/calculate-the-number-of-months-difference-between-two-dates/190647 "2010-06-24T14:29:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tom-mac](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/bc8723/32.png) [@tom-mac](https://www.ruby-forum.com/u/tom-mac)\
**Post date:** [June 24, 2010, 2:29pm UTC](https://www.ruby-forum.com/t/calculate-the-number-of-months-difference-between-two-dates/190647/1 "2010-06-24T14:29:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![tom-mac](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/bc8723/32.png) [@tom-mac](https://www.ruby-forum.com/u/tom-mac)\
**Post date:** [June 24, 2010, 3:19pm UTC](https://www.ruby-forum.com/t/calculate-the-number-of-months-difference-between-two-dates/190647/2 "2010-06-24T15:19:03Z")

</div>

On 24 June 2010 13:29, Tom M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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](http://www.francisfish.com/getting_the_number_of_months_between_two_dates_in_rubyrails.htm)

…and loads of other likely candidates.
