Excel does not have a built-in DATEDIF function in its function list, but the function still works if you type it manually. To get the difference between two dates in years, months, or days, use =DATEDIF(start_date, end_date, unit) where unit is "Y", "M", or "D". If you prefer a fully supported function, use =YEARFRAC for fractional years or =DAYS for total days. This guide shows both the hidden DATEDIF method and the supported alternatives, so you can calculate ages, tenures, and elapsed time without errors.
What You'll Need
- Microsoft Excel (any recent desktop version) or Excel for the web
- Two valid dates in separate cells, entered in a format Excel recognises (for example 01/15/2024 or 2024-01-15)
- Basic familiarity with typing formulas into the formula bar
Step-by-Step
- Enter your start and end dates. Put the earlier date in one cell (say A2) and the later date in another (say B2). Make sure both are real dates, not text. If a date is left-aligned in the cell, Excel may be treating it as text; retype it as a date or use Date > Text to Columns to convert it.
- Type DATEDIF manually. Click the cell where you want the result, type =DATEDIF(A2,B2,"Y") and press Enter. Because DATEDIF is a compatibility function, it will not appear in the AutoComplete dropdown or the Insert Function dialog, but Excel accepts it when typed directly.
- Choose the unit you need. Replace "Y" with "M" for whole months, "D" for total days, "YM" for months ignoring years, "MD" for days ignoring months and years, or "YD" for days ignoring years. For example, =DATEDIF(A2,B2,"M") returns complete months between the dates.
- Use a supported alternative for total days. If you only need the number of days, type =DAYS(B2,A2) or simply =B2-A2. Both are fully documented and appear in the function list.
- Use YEARFRAC for fractional years. Type =YEARFRAC(A2,B2,1) to get the difference as a decimal number of years. The third argument sets the day-count basis; 1 means actual days over actual days. Multiply by 12 for fractional months.
- Build whole years and months with a formula if needed. For a full "X years, Y months" result without DATEDIF, combine =INT(YEARFRAC(A2,B2,1)) for years with a month calculation using =DATEDIF or a manual formula based on EDATE. If you avoid DATEDIF entirely, compute months with =(YEAR(B2)-YEAR(A2))*12+MONTH(B2)-MONTH(A2) and adjust for day-of-month differences.
- Format the result cell. Select the result cell, right-click, choose Format Cells, and set the category to Number or General so the output displays as a number rather than a date.
- Copy the formula down. Drag the fill handle to apply the formula to other rows. Use absolute references (for example $A$2) only if you need every row to compare against the same start date.
Common Mistakes
- Typing the unit without quotes. DATEDIF requires the unit as text, so "Y" must be in quotation marks. Writing =DATEDIF(A2,B2,Y) returns an error.
- Reversing the dates. If the start date is later than the end date, DATEDIF returns a #NUM! error.
- Using text instead of dates. Dates stored as text produce #VALUE! errors. Check alignment and convert them.
- Expecting DATEDIF in the function list. It is intentionally undocumented and hidden from the wizard, so searching for it in Insert Function will not find it.
- Assuming "MD" is reliable. The "MD" unit can return unexpected results in some edge cases; test your output against known dates before relying on it.
Tips
- Use the Formula Bar's tooltip or press Ctrl+Shift+A after typing =DATEDIF( to see the argument names.
- For age calculations, =DATEDIF(birthdate,TODAY(),"Y") gives completed years as of today.
- If you share the workbook with people using other spreadsheet apps, prefer DAYS or YEARFRAC, since DATEDIF support varies outside Excel.
- Wrap formulas in IFERROR to hide errors when dates are missing: =IFERROR(DATEDIF(A2,B2,"Y"),"").
Troubleshooting
- #NAME? error: The function name is misspelled or the unit is missing quotes. Retype the formula exactly.
- #NUM! error: The start date is after the end date, or the unit is invalid. Swap the dates or check the unit code.
- #VALUE! error: One or both cells contain text rather than a date. Convert them with Date > Text to Columns or retype them.
- Result shows as a date: Change the cell format to General or Number.
- Formula works in one file but not another: Check that the workbook is saved in a modern format (.xlsx) and that calculation is set to Automatic under Formulas > Calculation Options.
Frequently Asked Questions
Why is DATEDIF not in Excel's function list?
DATEDIF is a legacy compatibility function kept for workbooks created in older spreadsheet programs. Microsoft supports it but does not list it in the Insert Function dialog, so it must be typed manually.
Does DATEDIF work in Excel for the web?
Yes, typing =DATEDIF with valid dates and a quoted unit works in Excel for the web, though it still will not appear in the function suggestions.
What is the best replacement for DATEDIF?
Use DAYS for total days and YEARFRAC for fractional years. For whole months or combined years-and-months output, DATEDIF remains the simplest option, or you can build the calculation with YEAR, MONTH, and DAY.
Can I calculate age without DATEDIF?
Yes. =INT(YEARFRAC(birthdate,TODAY(),1)) returns completed years and is fully documented.
Why does DATEDIF return a different month count than I expected?
DATEDIF counts complete units. If the end day is earlier in the month than the start day, the final partial month is not counted. Adjust your expectation or use a day-level formula if you need partial months.