javascript get distance between months

Solutions on MaxInterview for javascript get distance between months by the best coders in the world

showing results for - "javascript get distance between months"
Leonie
02 Aug 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