Created
January 22, 2016 16:24
-
-
Save nmenag/2635103dda97605ece44 to your computer and use it in GitHub Desktop.
Method for calculate the years and the months between two dates
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def date_diff(date1, date2) | |
| month = (date2.year * 12 + date2.month) - (date1.year * 12 + date1.month) | |
| month.divmod(12) | |
| end | |
| #for get the years | |
| date_diff(date, Date.today)[0] | |
| #for get the months | |
| date_diff(date, Date.today)[1] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment