Answers for "check if the difference between two dates is more than 1 month in javascript"

1

javascript date difference in months

function monthDiff(d1, d2) {
    var months;
    months = (d2.getFullYear() - d1.getFullYear()) * 12;
    months -= d1.getMonth();
    months += d2.getMonth();
    return months <= 0 ? 0 : months;
}
Posted by: Guest on May-27-2020
0

check if the difference between two dates is more than 1 month in javascript

const diffInMonths = (end, start) => {
   var timeDiff = Math.abs(end.getTime() - start.getTime());
   return Math.round(timeDiff / (2e3 * 3600 * 365.25));
}

const result = diffInMonths(new Date(2015, 3, 28), new Date(2015, 1, 25));

// shows month difference as integer/number
console.log(result);
Posted by: Guest on August-11-2021

Code answers related to "check if the difference between two dates is more than 1 month in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language