How To Calculate Days Between Dates In Excel (2026)
Excel can tell you how many days, months or years sit between two dates in a single formula.
The simplest method is plain subtraction, and the DATEDIF function handles complete months and years.
This guide shows each formula, the unit codes, workdays, elapsed time and the errors to watch for.
Table of Contents
- Quick answer: formulas for the gap between two dates
- Subtract one date from another
- Use DATEDIF for days, months and years
- DATEDIF unit codes
- Count weeks between two dates
- Show an age in years, months and days
- Avoid the “MD” problem
- Count to or from today with TODAY()
- Count workdays with NETWORKDAYS.INTL
- Calculate elapsed time
- Fix the #NUM! error
- Sources
- More Word, Excel and PowerPoint guides
Quick answer: formulas for the gap between two dates
| You want | Formula pattern |
|---|---|
| Days | =End date cell – Start date cell, or =DATEDIF(start,end,”d”) |
| Complete months | =DATEDIF(start,end,”m”) |
| Complete years | =DATEDIF(start,end,”y”) |
| Weeks | =DATEDIF(start,end,”d”)/7 |
| Workdays | =NETWORKDAYS.INTL(start,end,1) |
| Hours and minutes | =End time cell – Start time cell, formatted as [h]:mm |
Subtract one date from another
Excel stores dates as serial numbers, so subtraction gives you the number of days directly.
Subtract the earlier date from the later date to get a positive result.
- Type the start date in one cell and the end date in another.
- In a third cell, type an equals sign, click the end date cell, type a minus sign and click the start date cell.
- Press Enter, and format the result cell as a number if Excel shows a date.
If the result looks like a date, our guide on dates showing as numbers or hash marks in Excel explains the formatting.
Use DATEDIF for days, months and years
DATEDIF has three arguments, which are the start date, the end date and a unit code in quotation marks.
The syntax is DATEDIF(start_date, end_date, unit).
Microsoft warns that the function exists to support older Lotus 1-2-3 workbooks and may return incorrect results in certain scenarios.
DATEDIF unit codes
| Unit | What it returns |
|---|---|
| “Y” | Complete years in the period |
| “M” | Complete months in the period |
| “D” | Days in the period |
| “YM” | Months between the dates, ignoring days and years |
| “YD” | Days between the dates, ignoring years |
| “MD” | Days between the dates, ignoring months and years; Microsoft does not recommend it |
Microsoft shows start 6/1/2001 and end 8/15/2002 returning 440 with “D” and 75 with “YD”.
Another example from the same page returns 2 with “Y” for 1/1/2001 to 1/1/2003.
Count weeks between two dates
Divide the day count by seven, because a week has seven days.
For example, =DATEDIF(D13,E13,”d”)/7 gives a decimal such as 122.29 in Microsoft’s sample.
To show two decimal places, press Ctrl+1, select Number, and set Decimal places to 2.
Show an age in years, months and days
- Use =DATEDIF(D17,E17,”y”) for the total years, which returns 2 in Microsoft’s example.
- Use =DATEDIF(D17,E17,”ym”) for the months left over after the last full year, which returns 4.
- Use the day workaround in the next section for the remaining days, which returns 5.
To join them into one cell, use =DATEDIF(D17,E17,”y”)&” years, “&DATEDIF(D17,E17,”ym”)&” months, “&DATEDIF(D17,E17,”md”)&” days”.
The result in the sample is 2 years, 4 months, 5 days.
Press Alt+Enter to add line breaks while editing a long formula, and Ctrl+Shift+U to expand the formula bar.
Avoid the “MD” problem
The “MD” unit can return a negative number, zero or a wrong result.
Microsoft’s workaround is to subtract the first day of the end date’s month from the end date.
With an end date of 5/6/2016 in E17, DATE(YEAR(E17),MONTH(E17),1) gives 5/1/2016, and 5/6/2016 minus 5/1/2016 equals 5 days.
Count to or from today with TODAY()
Swap a fixed date for TODAY() to measure against the current date.
An example is =DATEDIF(TODAY(),D28,”y”), which counts complete years from today to the date in D28.
TODAY() reads the computer’s date, so the answer changes whenever the file is reopened on a later day.
Count workdays with NETWORKDAYS.INTL
- Optional: list your holiday dates in a separate range, select them, choose Formulas > Define Name, and name the range MyHolidays.
- Enter the start date and end date in two cells.
- Type =NETWORKDAYS.INTL(D53,E53,1) to treat Saturday and Sunday as the weekend.
- To skip holidays, type =NETWORKDAYS.INTL(D53,E53,1,MyHolidays).
In Microsoft’s example, 1/1/2016 to 12/31/2016 returns 261 workdays, and 252 once the holidays are excluded.
Pick a different weekend code from the formula suggestions, such as 2 for Sunday and Monday.
Calculate elapsed time
| Case | Steps |
|---|---|
| Times only | Enter times such as 7:15 AM and 4:30 PM, subtract with =E80-D80, then format as Custom h:mm |
| Dates and times | Enter full date and time values, subtract, then format the result as Custom [h]:mm to show 25 hours instead of 1:00 |
Microsoft’s time example returns 9:15, and its dates-and-times example returns 1.041666667 before formatting.
Fix the #NUM! error
DATEDIF returns #NUM! when the start date is later than the end date.
Swap the start and end cells so the earlier date comes first.
For other formula errors, see our guide to #N/A, #VALUE! and #REF! errors in Excel.
You can also wrap the result with the IF function to show a message when the dates are in the wrong order.
Sources
Microsoft Support: Calculate the difference between two dates and DATEDIF function.
More Word, Excel and PowerPoint guides
- How To Fix Dates Showing As Numbers Or ##### In Excel (2026)
- How To Save Word And Excel Files To Your PC By Default (2026)
- How To Show The Formula Bar And Gridlines In Excel (2026)
- How To Fix Excel Arrow Keys Scrolling The Sheet (2026)
- How To Fix Excel Column Headings Showing Numbers (2026)
- Excel Error: There Isn't Enough Memory To Complete This Action