To calculate the number of calendar days between two dates, normalize each year/month/day to UTC midnight, subtract the timestamps, and divide by 86,400,000. Using UTC avoids daylight-saving transitions turning a local calendar day into 23 or 25 elapsed hours.
const MS_PER_DAY = 86_400_000;
const start = Date.UTC(2026, 8, 10);
const end = Date.UTC(2026, 8, 18);
console.log((end - start) / MS_PER_DAY); // 8The original project read two text fields and used split(). An input type="date" gives a predictable YYYY-MM-DD value, which can still be split into numeric parts. Those parts can then be used with the JavaScript Date object or normalized directly with Date.UTC().
const [year, month, day] = value.split("-").map(Number);The older approach created local Date objects and divided the timestamp difference by 24 hours. That can be off around daylight-saving changes. For date-only arithmetic, Date.UTC() gives a stable midnight reference for each calendar date.
function toUtcDay(value) {
const [year, month, day] = value.split("-").map(Number);
return Date.UTC(year, month - 1, day);
}A signed difference tells you direction: positive means the end date is later; negative means it is earlier. Use Math.abs() only when direction does not matter.
const signedDays = (endUtc - startUtc) / MS_PER_DAY;
const absoluteDays = Math.abs(signedDays);“Days between calendar dates” and “complete 24-hour periods between two date-times” are different questions. UTC-midnight normalization is appropriate for calendar dates. For exact elapsed time between timestamps, subtract the actual timestamps and keep the result in milliseconds or the required duration units.
const elapsedMs = endDate.getTime() - startDate.getTime();
const elapsedHours = elapsedMs / (60 * 60 * 1000);Math.floor() or Math.round() to hide a timezone error; normalize the calendar dates correctly first.The same calculation can be connected to the custom date-picker projects. See the browsable date-picker tutorial and the existing calendar date-difference demo.
The original downloadable example is still available: 
Date Reference All Date Projects
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.