How would I work out the difference for two Date() objects in JavaScript, while only return the number of months in the difference?
Any help would be great :)
How would I work out the difference for two Date() objects in JavaScript, while only return the number of months in the difference?
Any help would be great :)
Consider each date in terms of months, then subtract to find the difference.
This will get you the difference of months between the two dates, ignoring the days.
Sometimes you may want to get just the quantity of the months between two dates totally ignoring the day part. So for instance, if you had two dates- 2013/06/21 and 2013/10/18- and you only cared about the 2013/06 and 2013/10 parts, here are the scenarios and possible solutions:
1.If you want just the number of the months between the two dates excluding both month1 and month2
2.If you want to include either of the months
3.If you want to include both of the months
Difference in Months between two dates in JavaScript:
total months between start_date and end_date :
Following code returns full months between two dates by taking nr of days of partial months into account as well.
See what I use: