difference in months between two dates in javascript

Solutions on MaxInterview for difference in months between two dates in javascript by the best coders in the world

showing results for - "difference in months between two dates in javascript"
Joelle
09 Feb 2019
1function monthDiff(d1, d2) {
2    var months;
3    months = (d2.getFullYear() - d1.getFullYear()) * 12;
4    months -= d1.getMonth();
5    months += d2.getMonth();
6    return months <= 0 ? 0 : months;
7}
8