Date Duration Calculator – Days Between Two Dates
Calculate the exact number of days, weeks, months, and business days between any two calendar dates.
How to Calculate Duration Between Dates
Our online Date Duration Calculator computes the precise elapsed time between any two dates. Whether planning project deadlines, counting business turnaround times, or tracking milestones, it delivers instantaneous, leap-year-accurate results.
(function() {
const startEl = document.getElementById(‘mtp_start_date’);
const endEl = document.getElementById(‘mtp_end_date’);
const incEl = document.getElementById(‘mtp_include_end_date’);
const now = new Date();
const nextMonth = new Date(now.getFullYear(), now.getMonth() + 1, now.getDate());
startEl.value = now.toISOString().split(‘T’)[0];
endEl.value = nextMonth.toISOString().split(‘T’)[0];
function update() {
const d1 = new Date(startEl.value + ‘T00:00:00’);
const d2 = new Date(endEl.value + ‘T00:00:00’);
if (isNaN(d1) || isNaN(d2)) return;
const addEnd = incEl.checked ? 1 : 0;
const msPerDay = 1000 * 60 * 60 * 24;
const diffMs = Math.abs(d2 – d1);
let totalDays = Math.round(diffMs / msPerDay) + addEnd;
const minDate = d1 < d2 ? d1 : d2;
const maxDate = d1 < d2 ? d2 : d1;
let y = maxDate.getFullYear() – minDate.getFullYear();
let m = maxDate.getMonth() – minDate.getMonth();
let d = maxDate.getDate() – minDate.getDate() + addEnd;
if (d < 0) {
m–;
const prevMonth = new Date(maxDate.getFullYear(), maxDate.getMonth(), 0);
d += prevMonth.getDate();
}
if (m < 0) {
y–;
m += 12;
}
let cur = new Date(minDate);
let weekdays = 0;
let weekends = 0;
for (let i = 0; i < totalDays; i++) {
const day = cur.getDay();
if (day === 0 || day === 6) weekends++;
else weekdays++;
cur.setDate(cur.getDate() + 1);
}
document.getElementById('mtp_duration_days').innerText = totalDays.toLocaleString() + ' Days';
document.getElementById('mtp_duration_breakdown".innerText = y + ' years, ' + m + ' months, ' + d + ' days';
document.getElementById('mtp_duration_weeks').innerText = (totalDays / 7).toFixed(1);
document.getElementById('mtp_duration_hours').innerText = (totalDays * 24).toLocaleString();
document.getElementById('mtp_duration_weekdays').innerText = weekdays.toLocaleString();
document.getElementById('mtp_duration_weekends').innerText = weekends.toLocaleString();
}
startEl.addEventListener('change', update);
endEl.addEventListener('change', update);
incEl.addEventListener('change', update);
update();
})();
