A DATEDIF calculator writes the Excel formulas for the gap between two dates and shows you what each one returns before it goes near your sheet. The usual reason to want one is an HR sheet: start dates in column A, today or a leaving date in column B, and a service column that has to read "3 years, 4 months, 12 days" on every row. That includes the people who joined on the 31st, which is where the formula most tutorials give you falls over.
How to use the DATEDIF calculator
- Pick the start date and the end date.
- Enter the cells that hold those dates in your sheet. It assumes A2 and B2. If the dates aren't in cells at all, tick "Write the dates into the formulas with DATE() instead", and each formula carries its own dates, like
=NETWORKDAYS(DATE(2024,1,31),DATE(2026,3,1)).
- For working days that skip public holidays, type the range that lists them: a defined name such as
Holidays, or an address like F2:F12. Leave it empty for weekends only.
- Read the five results. Each one shows the number, the formula and a line explaining each part. Press "Copy formula" on the one you need and paste it into your cell. "Copy all formulas" copies all five as label and formula separated by a tab, so pasted into Excel the labels fill one column and the working formulas the next. They point at your start and end cells, so paste them anywhere except on top of those.
Nothing is uploaded. The calculator works everything out in your browser, with no sign-up and no limit on how often you use it.
A formula with DATE() inside returns the same answer in every row you fill it into, so for a whole column of dates, use the cell references.
What each result counts
| Result | Formula (start in A2, end in B2) | What it counts |
|---|
| Days | =DATEDIF(A2,B2,"d") | Days from start to end, not counting the start day. =B2-A2 gives the same number. |
| Complete months | =DATEDIF(A2,B2,"m") | Whole months only. 31 January to 28 February is 0, because the 31st hasn't come round again. |
| Complete years | =DATEDIF(A2,B2,"y") | Whole years only, so someone whose birthday is tomorrow is still a year short. 29 Feb 2020 to 28 Feb 2021 is 0 years, 11 months. |
| Years, months and days | see below | Whole years, the months left over, then the days left over. |
| Working days | =NETWORKDAYS(A2,B2) | Monday to Friday, counting both the start and the end date. With a holidays range it becomes =NETWORKDAYS(A2,B2,Holidays). |
The years-months-days result is one formula that joins three counts with text:
=DATEDIF(A2,B2,"y")&" years, "&DATEDIF(A2,B2,"ym")&" months, "&(B2-EDATE(A2,DATEDIF(A2,B2,"m")))&" days"
DATEDIF(A2,B2,"y") // whole years
DATEDIF(A2,B2,"ym") // months left after those years
B2-EDATE(A2,DATEDIF(A2,B2,"m")) // EDATE moves the start forward by every whole month; the end date minus that is the days left
We checked the page's numbers against Excel for Mac on 12 date pairs, month ends and leap days among them. Every value matched.
Why DATEDIF "md" returns negative days
The "md" unit is the standard way to get the leftover days, and it breaks when two things line up: the end date's day number is lower than the start date's, and the month before the end date is too short to hold the start's day. 31 January to 1 March qualifies; 31 January to 31 March doesn't, and there "md" correctly gives 0. Microsoft's own DATEDIF page says it outright: "The "MD" argument may result in a negative number, a zero, or an inaccurate result."
Tutorials hand it out anyway. The common years-months-days formula joins "y", "ym" and "md", and with a start date mid-month it looks fine, because every month has a 15th or a 20th. Try month-end dates in Excel and you get this:
| Start | End | "md" returns | Correct leftover |
|---|
| 31 Jan 2026 | 1 Mar 2026 | -2 | 1 day |
| 30 Jan 2026 | 1 Mar 2026 | -1 | 1 day |
| 31 Jan 2024 | 1 Mar 2026 | -2 | 1 day (2 years, 1 month, 1 day) |
| 29 Feb 2024 | 1 Mar 2025 | 0 | 1 day (1 year, 0 months, 1 day) |
A service column with a -2 in it gets noticed. The zero is worse, because nobody questions a 0.
The calculator never uses "md". It takes the whole months with "m", moves the start date forward by that many months with EDATE, and subtracts the result from the end date. When "md" would have given a different answer for your dates, the page tells you: for 31 January to 1 March 2026 it warns that "md" returns -2, not 1. Otherwise a note under the results explains why it avoids "md".
Why your date difference looks wrong in Excel
One day short. DATEDIF with "d" and plain subtraction count the gap between the dates, so the same date twice is 0 days. NETWORKDAYS counts both ends, so the same weekday twice is 1 working day. For "how many days does the contract run, first and last day included", add one: =B2-A2+1.
Zero months. Month-end starts give short answers with "m" and "y", as the results table shows. DATEDIF does this in Excel too; the calculator isn't rounding differently.
A date instead of a number. A day count showing as a date in the early 1900s means the result cell is formatted as a date. Set it to General (Home > Number Format > General).
#NUM!. The end date is before the start date. DATEDIF won't count backwards. The calculator stops you with "The end date is before the start date. DATEDIF returns #NUM! that way round, so swap them."
Excel won't accept the formula when you press Enter. In an Excel set to use semicolons between arguments (common in German and French setups), every comma has to become a semicolon. If the separators are right, check the dates themselves: =ISNUMBER(A2) returns FALSE when a "date" is really text, and text Excel can't read as a date gives #VALUE!.
Doing it in Excel without the calculator
Type =DATEDIF( in full. It doesn't appear in autocomplete or under Formulas > Insert Function, which is why people conclude their copy of Excel doesn't have it, but it works in every current version. NETWORKDAYS and EDATE are listed normally under Formulas > Date & Time. For days alone, =DAYS(B2,A2) is the listed alternative; note that it takes the end date first.
For one unit you know by heart, typing the formula is faster than any calculator. The calculator earns its place on the years-months-days string, and for checking a month-end pair before you fill a formula down 400 rows.
Two Excel details for the working-days formula. The holidays have to be real dates, one per cell. And a defined name (Formulas > Define Name) keeps pointing at the same cells when you fill the formula down, where a plain F2:F12 slides to F3:F13 on the next row unless you write it as $F$2:$F$12.
What it can't do
- The working-days number on the page ignores holidays. It can't see the dates in your holidays range, so Excel's count may come out lower, and the page says so.
- Weekends are Saturday and Sunday only. For a Friday-Saturday weekend, change the pasted formula to NETWORKDAYS.INTL with weekend code 7, as in
=NETWORKDAYS.INTL(A2,B2,7).
- The years-months-days formula writes fixed words, so Excel shows "1 months, 1 days" where the page shows "1 month, 1 day".
- The end date can't be before the start date.
- Dates come from your browser's date picker.
- Formulas use commas between arguments. In a semicolon locale, swap them after you paste.
Each function has a full page with more examples: DATEDIF, NETWORKDAYS and EDATE. If you're scheduling rather than measuring, the Gantt chart generator counts durations inclusively, weekends included: its End column is start plus days minus one, so a 10-day task starting 29 September ends 8 October.
Questions
How do I calculate years, months and days between two dates in Excel?
Join three parts: DATEDIF with "y" for whole years, DATEDIF with "ym" for the months left over, and B2-EDATE(A2,DATEDIF(A2,B2,"m")) for the days after the last whole month. The full formula is =DATEDIF(A2,B2,"y")&" years, "&DATEDIF(A2,B2,"ym")&" months, "&(B2-EDATE(A2,DATEDIF(A2,B2,"m")))&" days". Most tutorials use DATEDIF with "md" for the days instead, which goes wrong around month ends.
Why is DATEDIF not showing in Excel?
DATEDIF is left out of Excel's formula autocomplete and the Insert Function dialog, but it works in every current version. Type it in full, such as =DATEDIF(A2,B2,"d"), and press Enter. The unit goes in quotes: "d", "m", "y", "ym" and so on.
Why does DATEDIF "md" return a negative number?
Because "md" goes wrong when the end date's day number is lower than the start date's and the month before the end date is too short to hold the start's day, such as a 31st followed by February. In Excel, 31 January 2026 to 1 March 2026 gives -2 with "md", where the right leftover is 1 day. Microsoft's own documentation warns that "md" may return a negative number, a zero or an inaccurate result. Subtract EDATE(start, whole months) from the end date instead.
Why does DATEDIF return #NUM!?
DATEDIF returns #NUM! when the start date is later than the end date. It won't count backwards, so swap the two dates. The same error appears if the unit is misspelled.
Does NETWORKDAYS include the start date?
Yes, NETWORKDAYS counts both the start date and the end date when they fall on weekdays. The same weekday entered twice gives 1 working day, while DATEDIF with "d" and plain subtraction give 0. Across a Monday-to-Friday week, NETWORKDAYS gives 5 and subtraction gives 4.
Why does DATEDIF say 0 months between 31 January and 28 February?
DATEDIF's "m" unit takes the difference in calendar months, then subtracts one when the end date's day number is lower than the start date's. 31 January to 28 February is one calendar month apart and 28 is lower than 31, so it gives 0, while 31 January to 1 March gives 1. The same rule makes 29 February 2020 to 28 February 2021 come out as 0 years and 11 months.
Why does my DATEDIF result show as a date?
The result cell is formatted as a date, so Excel displays the day count as a date: 760 days shows up as 29 January 1902. Change the cell's format to General on the Home tab and the number appears. The formula itself is fine.