Smart Systems for Home

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

Date Dif Excel: How to Calculate Days Between Two Dates

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

To find the difference between two dates in Excel, the fastest way is to subtract the start date from the end date using a simple formula (e.g., =B1-A1). For more specific intervals like months or years, use the DATEDIF function, which calculates the difference between two dates based on a specific unit of time.

What You'll Need

  • Microsoft Excel (any version)
  • A dataset containing at least two columns of dates
  • Dates formatted as "Date" cells rather than "Text"

Step-by-Step

  1. Prepare Your Data: Enter your start date in one cell (e.g., cell A2) and your end date in another cell (e.g., cell B2). Ensure the end date is later than the start date to avoid negative numbers.
  2. Method 1: Simple Subtraction (For Total Days):
    • Click on the cell where you want the result to appear.
    • Type =B2-A2 (assuming B2 is the end date and A2 is the start date).
    • Press Enter.
    • If the result looks like a date (e.g., 1/15/1900), go to the Home tab, locate the Number group, and change the dropdown menu from "Date" to "General" or "Number."
  3. Method 2: Using the DATEDIF Function (For Years, Months, or Days):
    • Click on the cell where you want the result.
    • Type the formula: =DATEDIF(A2, B2, "unit").
    • Replace "unit" with one of the following codes (keep the quotation marks):
      • "d": Total days between the two dates.
      • "m": Total complete months between the two dates.
      • "y": Total complete years between the two dates.
      • "md": The difference between the days in the start date and end date, ignoring months and years.
      • "ym": The difference between the months in the start date and end date, ignoring days and years.
    • Press Enter.
  4. Apply to Multiple Rows: Hover your mouse over the bottom-right corner of the result cell until a small black cross (the fill handle) appears. Click and drag the handle down to apply the formula to the rest of your date list.

Common Mistakes

  • Incorrect Date Order: In the DATEDIF function, the start date must always come before the end date. If the start date is later than the end date, Excel will return a #NUM! error.
  • Wrong Cell Formatting: A common point of confusion is when Excel automatically formats the result of a subtraction as a date. This happens because Excel stores dates as serial numbers; if the result cell is formatted as a date, it treats the number of days as a date starting from January 1, 1900. Always switch the format to "General" or "Number."
  • Text-Based Dates: If your dates were imported from another software, they might be stored as "Text." Excel cannot perform math on text. You can tell a date is text if it is left-aligned in the cell by default.
  • Missing Quotation Marks: In the DATEDIF formula, the unit (e.g., "y" or "m") must be enclosed in double quotation marks. Forgetting these will result in a #NAME? error.

Tips

  • Dynamic Dates: If you want to calculate the difference between a past date and today's date, use the TODAY() function. For example: =DATEDIF(A2, TODAY(), "d"). This will update automatically every time you open the spreadsheet.
  • Combining Units: To create a human-readable age or tenure (e.g., "2 Years, 3 Months, 5 Days"), you can combine multiple DATEDIF functions using the ampersand (&) symbol: =DATEDIF(A2, B2, "y") & " Years, " & DATEDIF(A2, B2, "ym") & " Months, " & DATEDIF(A2, B2, "md") & " Days".
  • Excluding Weekends: If you need the difference in working days only (excluding Saturdays and Sundays), use the NETWORKDAYS function instead: =NETWORKDAYS(A2, B2).

Troubleshooting

If your formula is not working as expected, try these steps in order:

  1. Check for #NUM! Error: Ensure the first date in your formula is the earliest date. Swap the cell references if necessary.
  2. Check for #VALUE! Error: This usually means one of the cells is not recognized as a date. Select the date cells, go to the Data tab, select Text to Columns, click Next twice to get to Step 3, select Date (MDY or DMY depending on your region), and click Finish. This forces Excel to convert text to date values.
  3. Check for #NAME? Error: Verify that you have spelled DATEDIF correctly and that the unit (like "y") is inside quotation marks.
  4. Verify Date Format: Ensure your system's regional date settings match the way the dates are typed (e.g., MM/DD/YYYY vs DD/MM/YYYY).

Frequently Asked Questions

Why is DATEDIF not listed in the Excel formula autocomplete?

DATEDIF is a "compatibility function" kept for users migrating from older spreadsheet software. Because of this, Excel does not show it in the formula suggestions as you type, but it still works perfectly if you type the full name and arguments manually.

How do I calculate the difference between two dates in hours?

Subtract the start date/time from the end date/time (e.g., =B2-A2) and then format the result cell. Right-click the cell, choose Format Cells, go to Custom, and type [h]:mm. The square brackets prevent the hours from resetting every 24 hours.

Can I use DATEDIF to find the number of weeks?

There is no specific "week" unit in DATEDIF. To find the number of weeks, calculate the total days using "d" and divide by 7. For example: =DATEDIF(A2, B2, "d")/7.

What is the difference between DATEDIF and NETWORKDAYS?

DATEDIF calculates the total calendar time (including weekends and holidays) between two dates. NETWORKDAYS calculates only the business days, automatically removing Saturdays and Sundays.

How do I ignore the time part of a date/time stamp?

If your cells contain both date and time (e.g., 01/01/2023 10:00 AM), use the INT function to strip the time. The formula would look like =DATEDIF(INT(A2), INT(B2), "d").