I was trying to do a basic date calculation as seen below. I want to find the remaining days in the month given the arguments below.
I thought I determined a solution, but there appears to be an extra 1/4 in the answer.
// returns last day of month
function lastDayOfMonth(date) {
return new Date(date.getFullYear(), date.getMonth() + 1, 0)
}
let day_start = new Date('2018-11-04');
let day_end = new Date('2019-01-10');
let day_last = lastDayOfMonth(day_start);
let total = 0;
if (day_end <= day_last) {
total = day_end - day_start;
} else {
total = day_last - day_start;
}
console.log(total / (1000 * 60 * 60 * 24)); // returns 26.25