Whether calculating project deadlines, rental periods, visa durations, or days until an event, knowing how many days between two dates is an everyday requirement. While you can count days on a calendar, leap years, varying month lengths (28, 30, or 31 days), and inclusive vs. exclusive counting rules often lead to off-by-one errors.
Our free Date Difference Calculator computes total days, weeks, months, and working days instantly. Here is how date calculation works and how to calculate it manually.
Inclusive vs Exclusive Date Counting
The most frequent source of confusion when counting days is deciding whether to count the start date, the end date, or both:
- Exclusive counting (Default): Measures the duration or time elapsed between two moments. (Example: Monday morning to Wednesday morning = 2 days).
- Inclusive counting (Both dates counted): Used in hotel bookings, event passes, and legal notices where day 1 and the final day both count. (Example: August 10 through August 12 = 3 days).
How to calculate days between dates in JavaScript
In software development, converting dates to UTC milliseconds avoids daylight saving time discrepancies:
const d1 = new Date("2026-08-10");
const d2 = new Date("2026-09-08");
const diffMs = Math.abs(d2 - d1);
const diffDays = Math.ceil(diffMs / (1000 * 60 * 60 * 24));
console.log(diffDays); // 29 daysBreaking down results into weeks and months
Beyond total day counts, users often need breakdowns:
- Total days: e.g. 45 days.
- Weeks + days: 6 weeks and 3 days (45 / 7 = 6 remainder 3).
- Business days: Excludes Saturdays and Sundays (roughly 5/7th of total days, minus national holidays).
For instant calculations with automatic leap year and timezone handling, use our free Date Difference Calculator or Business Days Calculator.
Frequently asked questions
Subtract the start timestamp from the end timestamp in milliseconds, divide by 86,400,000 (milliseconds in a day), and round down. Alternatively, use ToolOrbit's free Date Difference Calculator for instant results.
Exclusive counting measures the gap between dates (Aug 1 to Aug 3 = 2 days). Inclusive counting counts both boundary dates as active days (Aug 1 to Aug 3 = 3 days). Inclusive = Exclusive + 1.
Leap years add February 29th (making the year 366 days instead of 365). Any date span crossing Feb 29 in a leap year (e.g. 2024, 2028) contains one additional day.
Divide total days by 7: the quotient is whole weeks and the remainder is remaining days (e.g., 25 days = 3 weeks and 4 days).