Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Date Difference Calculator Excel Formula

· 4 min read · Home Tech

In this article
  1. Why Date Differences in Excel Can Be Tricky
  2. The DATEDIF Function: The Hidden Gem
  3. Simple Subtraction and Formatting
  4. Using NETWORKDAYS for Business Days
  5. Handling Errors and Edge Cases
  6. Comparing with Other Tools
  7. Frequently Asked Questions

The core Excel formula for calculating the difference between two dates is =DATEDIF(start_date, end_date, unit), where unit determines whether you get days, months, or years. Alternatively, a simple subtraction like =B2-A2 returns the number of days between the two dates, which you can then format as a number.

Why Date Differences in Excel Can Be Tricky

Excel stores dates as serial numbers, with January 1, 1900, being serial number 1. This means that subtracting one date from another is literally subtracting two numbers, which is why the result is a number of days. However, the display can be confusing: if you subtract two dates and the cell is formatted as a date, you'll see a date like 1/15/1900 instead of the number 15. Always format the result cell as a number or use a dedicated function to avoid this confusion.

The DATEDIF Function: The Hidden Gem

DATEDIF is a compatibility function from Lotus 1-2-3 that Excel still supports, but it doesn't appear in the function wizard or IntelliSense. You must type it manually. Its syntax is =DATEDIF(start_date, end_date, unit), where unit is a text code in quotes:

  • "d" – complete days
  • "m" – complete calendar months
  • "y" – complete years
  • "ym" – months remaining after full years
  • "yd" – days remaining after full years
  • "md" – days remaining after full months (ignores years and months)

For example, =DATEDIF(A2, B2, "y") returns the number of full years between the two dates. The "ym" and "md" variants are useful for age calculations, like "35 years, 4 months, and 12 days."

Simple Subtraction and Formatting

The most straightforward method is =B2-A2 where A2 is the start date and B2 is the end date. This returns the number of days. To display it as a plain number, select the cell, go to the Home tab, and choose "Number" from the dropdown. If you want the result in weeks, divide by 7: =(B2-A2)/7. For months, you could divide by 30.44 (average days per month), but that is approximate; DATEDIF with "m" gives exact calendar months.

Using NETWORKDAYS for Business Days

If you need the number of working days between two dates, use =NETWORKDAYS(start_date, end_date). This automatically excludes Saturdays and Sundays. You can also specify a range of holiday dates as a third argument: =NETWORKDAYS(start_date, end_date, holidays) where holidays is a range like $C$2:$C$10. This is ideal for project timelines, HR calculations, or invoice due dates.

Handling Errors and Edge Cases

DATEDIF returns a #NUM! error if the start date is after the end date. Simple subtraction returns a negative number in that case, which may be acceptable. Also, DATEDIF with "md" can return odd results near month boundaries (e.g., from January 31 to February 28 might show 28 days, not 0). For most purposes, "d" is the safest unit. If you see a date-like result, remember to change the cell format to Number.

Comparing with Other Tools

Google Sheets has the same DATEDIF function, so the formulas transfer directly. In Excel, you can also use the newer =DAYS(end_date, start_date) function, which is more intuitive because the argument order is clear. For years, you could use =YEARFRAC(start_date, end_date) to get a decimal (e.g., 2.5 years), which is useful for interest calculations or prorated amounts.

Frequently Asked Questions

Why does my date subtraction show a date instead of a number?

Because the cell is formatted as a date. Right-click the cell, choose Format Cells, select Number, and set decimal places to 0. The underlying value is correct; only the display is wrong.

How do I calculate age in years and months in Excel?

Use a combination: =DATEDIF(A2, TODAY(), "y") & " years, " & DATEDIF(A2, TODAY(), "ym") & " months". This gives a text string like "25 years, 3 months." The TODAY() function updates automatically.

What is the difference between DATEDIF and simple subtraction?

Simple subtraction returns the exact number of days (including fractions if times are involved). DATEDIF with "d" returns the same integer number of days, but DATEDIF with "m" or "y" counts complete months or years, which simple subtraction cannot do directly.

Can I calculate the difference in hours or minutes?

Yes, if your dates include times. Subtract the start datetime from the end datetime, then multiply by 24 for hours or by 1440 for minutes. For example, =(B2-A2)*24 gives hours. Format the result as a number.

Why does DATEDIF give a #NUM! error?

This happens when the start date is later than the end date. Check your cell references. Also, ensure both cells contain actual dates, not text. If a cell has text that looks like a date, Excel may not recognize it.