number of days between dates in react js code example
Example 1: subtracting two date objects in javacript
function findDayDifference(date1, date2) {
return Math.floor((Math.abs(date2-date1))/(1000*60*60*24));
}
Example 2: javascript difference between two dates in days
function dateDifference(date2, date1) {
const _MS_PER_DAY = 1000 * 60 * 60 * 24;
const utc1 = Date.UTC(date1.getFullYear(), date1.getMonth(), date1.getDate());
const utc2 = Date.UTC(date2.getFullYear(), date2.getMonth(), date2.getDate());
return Math.floor((utc2 - utc1) / _MS_PER_DAY);
}