How to Calculate Date Differences Using the DATEDIF Function in Excel

When you are managing a human resources database in Microsoft Excel and you need to calculate exactly how old an employee is based on their birthdate, or exactly how many days a specific invoice is past due, simple subtraction often fails due to leap years and varying month lengths. To force Excel to mathematically calculate the exact duration between two dates—and perfectly output the answer in your choice of Days, Months, or Years—you must use the hidden DATEDIF function.

The Hidden Nature of DATEDIF

The DATEDIF (Date Difference) function is a strange anomaly in Excel. It is a fully functional, highly advanced legacy formula, but Microsoft intentionally hides it from the user interface. If you start typing =DATEDIF, the standard autocomplete dropdown menu will completely ignore it, and there is no official tooltip to guide you. You must type the formula manually with absolute precision.

The syntax requires exactly three arguments: =DATEDIF(start_date, end_date, "unit")

Warning: The start_date must always be the older chronological date. If you reverse them, the formula will violently crash and output a #NUM! error.

Calculating Years, Months, and Days

Imagine cell A2 contains an employee’s hire date (01/15/2018), and cell B2 contains today’s date (09/04/2026).

To calculate exact Years (Tenure):
Use the "Y" (Years) unit flag. This calculates full, completed years, completely ignoring remaining months.

=DATEDIF(A2, B2, "Y")

Excel instantly outputs 8.

To calculate exact Months:
Use the "M" (Months) unit flag. This calculates the total number of full months that have passed between the two dates.

=DATEDIF(A2, B2, "M")

Excel outputs exactly 103.

To calculate exact Days:
Use the "D" (Days) unit flag. This is incredibly useful for tracking invoice aging or project deadlines.

=DATEDIF(A2, B2, "D")

Excel mathematically accounts for every single leap year between 2018 and 2026 and outputs the exact number of days: 3154.

Advanced Isolation Flags

The true power of DATEDIF lies in its ability to isolate specific units while ignoring others. If you want to know how many months have passed in the current, incomplete year of the employee’s tenure (ignoring the 8 full years they already worked), you use the "YM" (Months excluding Years) flag.

=DATEDIF(A2, B2, "YM")

Excel strips away the 8 completed years and outputs 7, telling you the employee has worked for 8 years and 7 months.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.