Excel has no DATEDIF listed in its AutoComplete or Function Wizard, but the function itself still works. Type =DATEDIF(start_date, end_date, unit) into a cell manually and press Enter, and Excel calculates the difference between two dates for you. It remains in the application for compatibility with older spreadsheets, which is why Microsoft does not document or advertise it, but it has not been removed. The catch is that it only accepts a start date that is earlier than or equal to the end date, and it will return a #NUM! error if you get that order wrong.
The reason people think the function is missing is that it does not appear anywhere in the interface. You cannot insert it from the formula list, it will not autocomplete, and the argument tooltip never appears. That makes it easy to assume it has been removed. If you would rather not rely on an undocumented function at all, Excel has fully documented alternatives using YEAR, MONTH, DAY, TODAY and NETWORKDAYS that cover the same ground. This guide shows both routes, starting with the syntax and unit codes for DATEDIF itself, then the replacement formulas for each of the common use cases. Formula names and cell references below work the same in Excel for Windows, Excel for Mac and Excel on the web, though labels and dialog wording can differ slightly by version.
What You'll Need
- Excel for Windows, Mac or the web (DATEDIF also works in Google Sheets, so the same syntax transfers)
- Two valid Excel dates in separate cells, or dates typed directly into the formula
- Dates entered in a format Excel recognises, such as 2024-03-15 or 15/03/2024 depending on your region settings
- A spare cell for the result and, if you plan to check answers, a calculator or a known reference date
Step-by-Step
- Check that your dates are real dates. Click a cell containing a date and look at the formula bar. If the bar shows a date such as 15/03/2024, it is a genuine date value. If it shows text like "March 15 2024" with an apostrophe, or the cell is left-aligned rather than right-aligned, Excel is treating it as text and DATEDIF will fail. Convert it first with
=DATEVALUE(cell)or by re-entering it using a recognised format. - Put the start date in one cell and the end date in another. For example, enter the earlier date in A2 and the later date in B2. Keeping them in cells rather than typing dates inside the formula makes the sheet easier to audit and update.
- Click an empty cell and type the DATEDIF formula by hand. Begin with an equals sign and type the whole name:
=DATEDIF(A2,B2,"Y"). Do not expect Excel to suggest DATEDIF as you type, because it will not. Ignore any warning that the name is unrecognised while the formula is half-typed; the warning disappears once the closing bracket is entered. - Press Enter and check the result. The third argument controls what is counted: "Y" returns complete years, "M" complete months, "D" total days, "YM" leftover months after whole years are removed, "MD" leftover days after whole months, and "YD" leftover days after whole years. The unit codes must be inside quotation marks, and they are not case-sensitive.
- Drag the formula down if you have a list. Use the fill handle in the bottom-right corner of the selected cell and drag down, or double-click the handle to fill to the end of the adjacent data. Relative references shift to A3, B3 and so on automatically.
- For a live age calculation, replace the end date with TODAY(). The formula
=DATEDIF(A2,TODAY(),"Y")returns the current age in full years and updates each time the workbook recalculates. Use a fixed end date instead if you need a result that does not change. - If you prefer documented functions, build the year difference instead.
=YEAR(B2)-YEAR(A2)gives the calendar-year gap, but subtract one when the end date falls before the start date's month and day:=YEAR(B2)-YEAR(A2)-IF(DATE(YEAR(B2),MONTH(A2),DAY(A2))>B2,1,0). This reproduces the "Y" unit with a formula Microsoft fully supports. - For complete months, use the month arithmetic version.
=(YEAR(B2)-YEAR(A2))*12+MONTH(B2)-MONTH(A2)gives the raw month count, then subtract one if the end day is before the start day:=(YEAR(B2)-YEAR(A2))*12+MONTH(B2)-MONTH(A2)-IF(DAY(B2)<DAY(A2),1,0). - For a plain day count, use subtraction.
=B2-A2returns the number of days between the dates and requires no special function at all. Format the result cell as General or Number so it does not turn into a date by accident. - For business days, use NETWORKDAYS.
=NETWORKDAYS(A2,B2)counts working days between the two dates, skipping Saturdays and Sundays. A third argument can point to a range of holiday dates to exclude as well. - For a combined years-and-months label, concatenate two DATEDIF results.
=DATEDIF(A2,B2,"Y")&" years "&DATEDIF(A2,B2,"YM")&" months"produces a readable string such as "3 years 7 months". The same result can be built from the documented year and month formulas above if you would rather avoid DATEDIF entirely.
Common Mistakes
- Swapping the dates. DATEDIF returns #NUM! whenever the start date is later than the end date. It does not produce negative numbers or flip the order for you.
- Forgetting the quotation marks around the unit. Writing
DATEDIF(A2,B2,Y)makes Excel look for a cell or name called Y and produces a #NAME? error. - Expecting autocomplete. DATEDIF will never show in the suggestion list, so a formula typed with a missing closing bracket is harder to spot. Check the bracket count before pressing Enter.
- Mixing up "M" and "YM". "M" gives total months, while "YM" gives only the leftover months after whole years are stripped out. Using "M" where "YM" is needed produces inflated answers in age and tenure formulas.
- Feeding it text dates. DATEDIF needs real serial date values. Text that looks like a date, such as imported data from another system, will return #VALUE!.
- Formatting the result cell as a date. A day count of 412 shown in a date-formatted cell appears as a random day in a year. Set the cell format to General or Number.
Tips
- The
DATEfunction builds dates reliably regardless of regional settings.DATE(2024,3,15)always means 15 March 2024, whereas a typed date may be read as month-first or day-first depending on your locale. - Name your date columns clearly as the start and end, and put the earlier date first in every row, so the formula logic never has to guess.
- Use
=ISNUMBER(A2)as a quick check on whether a column holds genuine dates; a TRUE result means the cell is a proper date value. - Wrapping a formula in
IFERRORsuch as=IFERROR(DATEDIF(A2,B2,"Y"),"check dates")replaces ugly error codes with a readable message. - If your end date might sit before the start date in some rows, use
MINandMAXinside the formula to sort the two automatically:=DATEDIF(MIN(A2,B2),MAX(A2,B2),"D").
Troubleshooting
You get #NAME? as soon as you press Enter. Either the function name is misspelled or a unit argument is missing its quotation marks. Rewrite the whole formula from scratch with DATEDIF in capitals and all three arguments present.
You get #NUM!. The start date is later than the end date. Check the two cells side by side; if they look correct, one of them may be text that Excel is misreading. Test with ISNUMBER to confirm.
You get #VALUE!. At least one argument is text or blank. Blank cells are treated as invalid here, so make sure both dates are filled in, or guard the formula with IF(A2="","",DATEDIF(...)).
The formula works in one workbook but not another. The second file may store dates as text, usually from a CSV import or a copy from another application. Select the column, use Data > Text to Columns and finish the wizard with the date format set to match your data to convert it in place.
The number looks wrong by one. Check whether the two cells include time values. A date with a time later than midnight can shift a day or month boundary. Strip times with INT(cell) before comparing.
You want a fully supported alternative. Replace each DATEDIF unit with the documented YEAR, MONTH and DAY formulas from the steps above. The results match, and the formulas appear in autocomplete and in Microsoft's own documentation.
Frequently Asked Questions
Why doesn't DATEDIF appear in Excel's function list?
It is retained for backward compatibility with workbooks created in older versions of Excel. Microsoft does not document it in current help pages, so it is hidden from the wizard and autocomplete, but the calculation engine still recognises it when typed directly.
Will a DATEDIF formula survive if I send the file to someone else?
Yes. The formula travels with the workbook and calculates normally in other copies of Excel and in Google Sheets. The risk is that a future version could drop the function, so the documented YEAR and MONTH equivalents are safer for long-lived templates.
Can I use DATEDIF to calculate someone's exact age?
Yes, with the "Y" unit and TODAY() as the end date. For a fuller answer, combine "Y", "YM" and "MD" to show years, months and days together in one label.
Does DATEDIF count the end date itself?
No. It counts complete units between the two dates and does not include the end date as an extra day. If you need an inclusive count, add one to a day difference, as in =B2-A2+1.
What is the difference between "D" and "MD"?
"D" returns the total number of days across the whole span. "MD" returns only the leftover days after whole months have been counted, which is why it is useful for a years-months-days breakdown but misleading on its own.
Can I use DATEDIF for times as well as dates?
Only loosely. It works on date serial numbers, so time portions can push results over a boundary. For hours and minutes, subtract one datetime from another and multiply by 24, then format the result as a number.