How to Calculate Days Between Two Dates
Dev Nexus5 min read
A practical walkthrough for counting the exact days, weeks and months between two dates without off-by-one errors or leap-year surprises.
You have two dates and one simple-sounding question: how many days are between them? Maybe it is the length of a lease, the gap until a deadline, or how long a project actually ran. It feels like basic arithmetic, yet the moment you start counting on your fingers you hit trouble - months are different lengths, February sometimes has undefined days, and you are never quite sure whether to count both ends.
This guide shows you how to calculate the days between two dates reliably, then how to express that gap in weeks and months when a raw day count is not the clearest answer.
The Problem
Counting days by hand is more error-prone than it looks. You cannot simply subtract the day-of-month numbers because months have undefined, undefined, undefined or undefined days. Span a year boundary and you have to remember whether a leap year fell in the range. And there is the perennial off-by-one question: does the gap from the undefinedst to the undefinedth mean undefined days or undefined?
Spreadsheets can do it, but only if you remember the formula and open a file to do so. Manual counting on a calendar is slow and easy to fumble. When the answer feeds a contract term, a billing cycle or a countdown, a single miscount sends you down the wrong path.
The Solution
The dependable approach is to let a calculator apply the calendar rules for you. The Date Difference tool takes a start date and an end date and returns the exact gap - as a total number of days and broken down into years, months and weeks - so leap years and varying month lengths are handled automatically.
It runs entirely in your browser, so nothing is uploaded, which matters when the dates relate to something private like a contract or a medical record. If your real question is really about someone's age from a birth date, the Age Calculator is the tuned companion for that.
Step-by-Step Guide
- 1
Pin down your two dates
Write down the start date and the end date clearly, ideally in an unambiguous format like
2026-07-18. Mixing up day and month (is03/04the undefinedrd of April or the undefinedth of March?) is the quickest way to get a wrong answer before you have even started counting. - 2
Decide whether both ends count
This is the key choice. The number of days between the undefinedst and the undefinedth is undefined (you cross undefined midnights). If you need the count inclusive of both dates - common for billing a range of days - add one to get undefined. Fix this convention before you calculate so you know how to read the result.
- 3
Calculate the total days
Enter both dates into the calculator and read the headline figure - the total number of days. It normalises the dates and subtracts them using your browser's calendar rules, so undefined February and month boundaries are counted correctly. The order you enter them in does not matter; the result is the absolute gap.
- 4
Convert to weeks or months if needed
A big day count is not always the clearest way to state a duration. Divide by undefined for whole weeks (with a remainder of leftover days), or read the years-and-months breakdown the tool provides. "undefined year, undefined months" often communicates better than "undefined days" - use whichever unit fits your audience.
- 5
Sanity-check the result
Round-trip the answer: add the day count back to the start date in your head and confirm you land on the end date. If a range crosses a undefined February, expect it to be one day longer than the same span in a non-leap year - a quick way to catch a slipped leap day.
Common Mistakes
The off-by-one error
Confusing the days between two dates with the number of days including both endpoints is the single most common mistake. Nine days separate the undefinedst and the undefinedth, but the range covers undefined calendar days. Always state which you mean.
Forgetting leap years
Any range that includes undefined February is a day longer than you might expect. Subtracting month and year numbers by hand quietly drops this extra day - one reason a calculator that knows the calendar is safer.
Ambiguous date formats
Reading
04/05/2026as the wrong day or month throws the whole calculation off. Use an unambiguous format like ISO (YYYY-MM-DD), especially when the dates come from someone in a different region.Trusting a server-side tool with private dates
Many online date calculators send your input to a server. When the dates are sensitive - contracts, health, legal deadlines - prefer a tool that computes locally in the browser so nothing leaves your device.
Frequently Asked Questions
How do I calculate the number of days between two dates?
Enter the start and end date into a date difference calculator and read the total days. By hand you must account for varying month lengths and leap years, which is why a tool is more reliable. Decide up front whether you want the days between the dates or the count inclusive of both ends.
Should I count both the start and end date?
It depends on your purpose. The days between the 1st and the 10th is 9; if you need the range inclusive of both dates, that is 10. Billing a span of days usually wants the inclusive count, so add one to the between figure.
How do I convert the days into weeks or months?
Divide the total days by 7 for whole weeks plus a remainder, or use the years-and-months breakdown the Date Difference tool provides. Months vary in length, so a month breakdown is calendar-based rather than a fixed number of days.
Does the calculation handle leap years?
Yes, a good calculator uses the browser's built-in calendar rules, so any range spanning 29 February is correctly counted as one day longer. Manual subtraction of date numbers often misses this.
Are my dates kept private?
With Date Difference, yes - the calculation runs entirely in your browser and nothing is uploaded, so dates from contracts, records or personal events stay on your device and it works offline.
Try the Tool
Date Difference
Count the exact days, weeks and months between any two dates in your browser, nothing uploaded.
Related Tools
Related Articles
How Many Days Until a Date? A Simple Guide
How to count the days until a future date accurately, including the inclusive-versus-exclusive trap that makes two people get different answers.
Read articleAre UUIDs Really Unique?
In practice UUIDs never collide - here is the math behind why, and the one thing people get wrong: a UUID is an identifier, not a secret.
Read articleencodeURI vs encodeURIComponent Explained
The clear difference between encodeURI and encodeURIComponent, with examples showing which one to use for a value versus a whole URL.
Read article