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}
1const diffInMonths = (end, start) => {
2 var timeDiff = Math.abs(end.getTime() - start.getTime());
3 return Math.round(timeDiff / (2e3 * 3600 * 365.25));
4}
5
6const result = diffInMonths(new Date(2015, 3, 28), new Date(2015, 1, 25));
7
8// shows month difference as integer/number
9console.log(result);
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