About this tool
Calculating the exact interval between two calendar dates is essential for project sprint planning, legal contract terms, wedding countdowns, and HR payroll cycles. However, Gregorian calendar rules—varying month lengths, 365-day common years, and February leap days—make mental calculation prone to off-by-one errors. This tool computes day, week, month, and year differences precisely with optional workday filtering.
How to Use This Tool (Step-by-Step)
Select Start and End Dates
Use the calendar picker to choose your start and target end dates, or click 'Today' for instant countdown comparisons.
Configure Inclusion Rule
Toggle whether to include the end date in the total duration (counting interval vs full inclusive days).
Inspect Multi-Unit Breakdown
Review the interval expressed in total days, weeks, full months, and remaining days. Copy the summary with one click.
Leap Year & Month Boundary Precision
Accounts for the complete Gregorian leap-year rule (divisible by 4 and 400, not 100), eliminating February 29th anomalies.
Workday / Business Day Filtering
Excludes Saturdays and Sundays to output pure working business days, indispensable for project milestones and sprint planning.
Human-Readable Multi-Scale Display
Concurrently breaks totals into both raw days and intuitive composite formats ('X years, Y months, Z days').
Calendar Gotchas & Legal Guidelines
- •Inclusive vs exclusive bounds: In legal contracts, terms frequently begin the day after signing (exclusive start). Always clarify boundary terms in agreements.
- •Beware of DST 23/25-hour shifts: Spring forward and fall back days do not possess 24 hours. Never calculate date boundaries with raw millisecond additions without calendar APIs.
- •Ambiguity of 'One Month': Adding 1 month to January 31st yields February 28/29th. Clarify whether rolling months anchor to calendar boundaries or fixed 30-day buckets.
Code & Transformation Examples
Representative Date Difference Breakdown
起始日: 2026-01-01 (元旦)
结束日: 2026-09-23 (今天)• 绝对相差: 265 天 (算头不算尾)
• 折合周数: 37 周 零 6 天
• 复合表述: 8 个月 零 22 天
• 纯工作日: 190 个工作日 (剔除周六周日)* Composite breakdown computes progressive monthly boundaries with exact day counts.
JavaScript Date Difference Implementation
function getDaysDiff(date1, date2) {
const MS_PER_DAY = 1000 * 60 * 60 * 24;
// 统一转为 UTC 午夜以规避夏令时 1 小时偏差
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);
}直接拿本地时间相减除以 86400000 可能会在跨越夏令时(DST)换季当天少算或多算 1 小时。务必使用 Date.UTC() 对齐。* Normalizing to UTC midnight guards against 23-hour and 25-hour days caused by Daylight Saving Time.
Frequently Asked Questions
Q: Why isn't 2026 a leap year? How are leap years defined?
A: Leap year rule: Years divisible by 4 are leap years, except centenary years not divisible by 400. 2026 is not divisible by 4, making it a common 365-day year. Next leap year is 2028.
Q: Does workday calculation consider public holiday shifts?
A: Default mode filters standard Saturdays and Sundays. Because regional public holidays and makeup days shift annually by decree, regional holiday datasets are required for dynamic bank schedules.
Q: How does the tool handle past vs future dates?
A: The tool recognizes chronological ordering automatically, displaying either 'X days remaining' (countdown) or 'X days have passed' (anniversary tracker).