How to Compute Date Difference in Excel
In this article
To compute the difference between two dates in Excel, subtract the earlier date from the later one (for example, =B2-A2) to get the number of days. For months or years, use =DATEDIF(A2,B2,"m") or =DATEDIF(A2,B2,"y"). For working days only, use =NETWORKDAYS(A2,B2). All three formulas assume your cells contain real Excel dates, not text.
What You'll Need
- Microsoft Excel on Windows, Mac, or the web app (the formulas below work in all three; labels in menus can differ slightly by version and region).
- Two cells that contain valid Excel dates — for example, A2 as the start date and B2 as the end date.
- Dates entered in a format Excel recognises (such as 1/15/2025 or 2025-01-15). If Excel left-aligns the value in the cell, it is probably text, not a date.
Step-by-Step
- Confirm both cells hold real dates. Click each cell and look at the formula bar. A real date shows a date value there. If the cell is formatted as Text, Excel will not calculate with it. To fix: select the cells, open the Home tab, open the Number Format dropdown, and choose Short Date or Long Date. If the value still will not convert, use Data > Text to Columns and finish the wizard with the Date column type selected.
- Pick an empty cell for the result. For example, C2. This is where the formula goes.
- Type the subtraction formula for total days. Enter
=B2-A2and press Enter. The result is the number of days between the two dates. If B2 is earlier than A2, you get a negative number — swap the cells or wrap the formula inABS(), as in=ABS(B2-A2). - Format the result as a number. If the answer appears as a date (for example, 1/15/1900), the result cell inherited a date format. With the cell selected, open the Home tab, open the Number Format dropdown, and choose General or Number. The value will now display as a plain day count.
- For whole months, use DATEDIF. Enter
=DATEDIF(A2,B2,"m"). This returns complete calendar months between the dates. For whole years, use=DATEDIF(A2,B2,"y"). For days ignoring months and years, use=DATEDIF(A2,B2,"d"). - For a combined years-months-days breakdown, chain DATEDIF. A common pattern is
=DATEDIF(A2,B2,"y")&" years, "&DATEDIF(A2,B2,"ym")&" months, "&DATEDIF(A2,B2,"md")&" days". The "ym" and "md" arguments return the remainder after whole years or months are counted. - For working days only, use NETWORKDAYS. Enter
=NETWORKDAYS(A2,B2). This counts Monday through Friday and excludes weekends. To skip holidays too, list the holiday dates in a separate range (say, E2:E10) and use=NETWORKDAYS(A2,B2,E2:E10). For a six-day week, useNETWORKDAYS.INTLand set the weekend argument. - For a precise elapsed time including hours, subtract with a time component. If A2 and B2 include times,
=B2-A2returns a fraction of a day. Multiply by 24 for hours:=(B2-A2)*24. Format the result cell as Number, not Date. - Copy the formula down. Drag the fill handle from the corner of the result cell to apply the same formula to other rows. Relative references adjust automatically.
Common Mistakes
- Dates stored as text. This is the most frequent cause of wrong answers or #VALUE! errors. Text dates look like dates but are left-aligned and will not subtract. Convert them with Text to Columns or by re-entering them in a recognised format.
- The result shows as a date. Excel copies the date format from the input cells. Change the result cell's format to General or Number.
- Reversed order.
=A2-B2when A2 is later gives a negative number. Decide which column is the start and keep it consistent. - Using DATEDIF with the wrong unit. DATEDIF counts complete units, so
"m"between 1/31 and 2/28 may return 0. It measures elapsed whole months, not calendar month changes. - Forgetting that NETWORKDAYS includes both endpoints. A Monday-to-Friday range returns 5, not 4. Subtract 1 if you want the number of nights or full days between them.
- Typing dates with a period or unusual separator. Depending on your region settings, 15.01.2025 may be read as text. Use the separator your system expects, or enter dates via the date picker.
Tips
- Press Ctrl+; (semicolon) on Windows or Cmd+; on Mac to insert today's date instantly.
- Use
=TODAY()-A2to compute age or elapsed days from a start date to today. The value updates each time the workbook recalculates. - Name your input cells (Formulas > Define Name) so formulas read like
=EndDate-StartDateand are easier to audit. - To count only Mondays, or any single weekday, between two dates, combine
NETWORKDAYS.INTLwith a custom weekend string, or useSUMPRODUCTwithWEEKDAY. - Keep a dedicated holidays range on a separate sheet and reference it absolutely (
$E$2:$E$10) so it copies down cleanly. - If you need the difference in weeks, divide the day result by 7 and wrap it in
INT()for whole weeks.
Troubleshooting
- #VALUE! error. One or both inputs are text, or contain a stray space. Check with
=ISNUMBER(A2); it should return TRUE. If FALSE, convert the cell as described in step 1. - #NUM! error from DATEDIF. The start date is later than the end date. Swap the arguments.
- Result is a strange date like 1/0/1900. The cell is formatted as a date. Change the number format to General.
- Result is a decimal. Times are included in the cells. Round with
=ROUND(B2-A2,0)or=INT(B2-A2)for whole days. - NETWORKDAYS counts a holiday you excluded. Confirm the holiday range contains real dates, not text, and that the range reference is correct.
- Formula copies but results do not change. Check whether the workbook is set to manual calculation. On the Formulas tab, open Calculation Options and set it to Automatic.
- If that did not work, rebuild the formula in a fresh cell using the date picker to enter both dates. This rules out hidden characters and formatting problems in the original cells.
Frequently Asked Questions
Why does my date difference show as a date?
The result cell has a date number format. Select it, open the Number Format dropdown on the Home tab, and choose General or Number.
How do I get the difference in months instead of days?
Use =DATEDIF(A2,B2,"m") for complete months. For a decimal month count, use =(B2-A2)/30.44, though that is an approximation because months vary in length.
Does DATEDIF appear in Excel's function list?
No. DATEDIF is a hidden, backwards-compatible function. It still works when typed manually, but it will not appear in the autocomplete list or the Insert Function dialog.
How do I exclude weekends and holidays?
Use =NETWORKDAYS(A2,B2,holidays), where holidays is a range of dates. For a non-standard weekend, use NETWORKDAYS.INTL with the weekend argument.
Can I subtract dates across different sheets?
Yes. Reference the sheet name in the formula, for example =Sheet2!B2-Sheet1!A2. If the sheet name contains spaces, wrap it in single quotes: ='Start Dates'!A2.
Why is the result one day off from what I expect?
Excel counts the difference between the two date serial numbers, so 1/1 to 1/2 returns 1. If you want an inclusive count of calendar days, add 1: =B2-A2+1. NETWORKDAYS already includes both endpoints.