Excel Calculate Number Of Days Between Two Dates

Excel Date Difference Calculator

Calculate the exact number of days between two dates with Excel formulas

Total Days Between Dates:
0
Excel Formula (Modern):
=DAYS(end_date, start_date)
Excel Formula (Legacy):
=DATEDIF(start_date, end_date, “d”)
Inclusive Count (if selected):
0

Complete Guide: How to Calculate Days Between Two Dates in Excel

Calculating the number of days between two dates is one of the most common tasks in Excel, whether you’re tracking project timelines, calculating employee tenure, or analyzing financial periods. This comprehensive guide will show you multiple methods to achieve this, including modern functions, legacy approaches, and advanced techniques for handling business days and holidays.

Quick Methods Overview

  • Modern Excel: =DAYS(end_date, start_date)
  • Legacy Excel: =DATEDIF(start_date, end_date, "d")
  • Simple Subtraction: =end_date - start_date
  • Network Days: =NETWORKDAYS(start_date, end_date)

Key Considerations

  • Excel stores dates as serial numbers (1 = Jan 1, 1900)
  • Time components are stored as fractional days
  • Leap years are automatically accounted for
  • Different Excel versions may handle 1900 differently

Method 1: Using the DAYS Function (Excel 2013 and Later)

The DAYS function is the most straightforward modern method to calculate days between dates:

=DAYS(end_date, start_date)

Where:

  • end_date – The later date (can be cell reference or date serial number)
  • start_date – The earlier date (can be cell reference or date serial number)

Example: If cell A2 contains 15-Jan-2023 and B2 contains 20-Feb-2023, the formula =DAYS(B2,A2) returns 36.

Method 2: Using Simple Subtraction

Since Excel stores dates as serial numbers, you can simply subtract one date from another:

=end_date - start_date

Example: =B2-A2 would give the same result as the DAYS function.

Method Formula Works In Handles Leap Years Includes Time
DAYS function =DAYS(end,start) Excel 2013+ Yes No
Subtraction =end-start All versions Yes Yes
DATEDIF =DATEDIF(start,end,”d”) All versions Yes No
NETWORKDAYS =NETWORKDAYS(start,end) All versions Yes No

Method 3: Using DATEDIF (Works in All Excel Versions)

The DATEDIF function is a hidden gem that works in all versions of Excel:

=DATEDIF(start_date, end_date, "d")

Where “d” returns the number of complete days between the dates.

Important Note: DATEDIF isn’t documented in Excel’s help files, but it’s been consistently available since Lotus 1-2-3 days. The function comes from Excel’s origins and is maintained for compatibility.

Advanced Techniques

Calculating Business Days (Excluding Weekends)

Use the NETWORKDAYS function to exclude weekends:

=NETWORKDAYS(start_date, end_date)

To also exclude specific holidays, add them as a range:

=NETWORKDAYS(start_date, end_date, holidays_range)

Calculating Years, Months, and Days Separately

Use DATEDIF with different unit codes:

=DATEDIF(start_date, end_date, "y") & " years, " &
DATEDIF(start_date, end_date, "ym") & " months, " &
DATEDIF(start_date, end_date, "md") & " days"
            

Handling Time Components

If your dates include time values and you want to calculate precise intervals:

= (end_datetime - start_datetime) * 24  ' for hours
= (end_datetime - start_datetime) * 24 * 60  ' for minutes
= (end_datetime - start_datetime) * 24 * 60 * 60  ' for seconds

Common Errors and Solutions

Error Cause Solution
#VALUE! Non-date values in formula Ensure both arguments are valid dates or date serial numbers
#NUM! Start date is after end date Swap the dates or use ABS function: =ABS(end_date-start_date)
###### Column too narrow to display result Widen the column or format as General
Incorrect count 1900 date system vs 1904 date system Check Excel options: File > Options > Advanced > “Use 1904 date system”

Practical Applications

Project Management

Calculate project durations, track milestones, and monitor timelines against deadlines. Use conditional formatting to highlight overdue tasks:

  1. Select your date range
  2. Go to Home > Conditional Formatting > New Rule
  3. Use formula: =TODAY()-A1>0 to highlight past dates

Human Resources

Track employee tenure for benefits eligibility, anniversary recognition, and contract renewals:

=DATEDIF(hire_date, TODAY(), "y") & " years, " & DATEDIF(hire_date, TODAY(), "ym") & " months"

Financial Analysis

Calculate interest periods, loan durations, and investment horizons:

=DAYS(maturity_date, issue_date)/365  ' for years
=DAYS(maturity_date, issue_date)/365*12  ' for months

Excel Date Systems Explained

Excel uses two different date systems that can affect your calculations:

1900 Date System (Windows default)

  • Day 1 = January 1, 1900
  • Incorrectly assumes 1900 was a leap year (it wasn’t)
  • Day 60 = February 29, 1900 (which didn’t exist)
  • Used by default in Windows versions of Excel

1904 Date System (Mac default)

  • Day 1 = January 1, 1904
  • Correctly handles leap years
  • Used by default in Mac versions of Excel
  • Can be changed in Excel preferences

Important: When sharing workbooks between Windows and Mac, check which date system is being used to avoid calculation discrepancies. You can check this in Excel Options under the Advanced tab.

Excel vs Other Tools

While Excel is powerful for date calculations, here’s how it compares to other tools:

Tool Date Calculation Strengths Limitations Best For
Excel Flexible formulas, handles complex scenarios, integrates with other data Steep learning curve for advanced functions, version differences Business analysis, financial modeling, project tracking
Google Sheets Similar functions to Excel, real-time collaboration, free Fewer advanced date functions, performance with large datasets Collaborative projects, simple calculations
Python (pandas) Precise datetime handling, time zone support, large dataset performance Requires programming knowledge, not visual Data science, automation, large-scale analysis
JavaScript Web-based applications, real-time updates, interactive visualizations Date handling quirks, time zone complexities Web applications, dynamic calculators

Best Practices for Date Calculations in Excel

  1. Always use cell references: Instead of hardcoding dates like =DAYS("1/15/2023","2/20/2023"), use cell references for flexibility.
  2. Format cells properly: Use Excel’s date formats (Short Date, Long Date) rather than text that looks like dates.
  3. Handle errors gracefully: Use IFERROR to manage potential errors: =IFERROR(DAYS(B2,A2),"Check dates")
  4. Document your formulas: Add comments to explain complex date calculations for future reference.
  5. Test with edge cases: Always test with dates that span month-end, year-end, and leap years.
  6. Consider time zones: If working with international dates, be explicit about time zones or convert to UTC.
  7. Use named ranges: For frequently used date ranges (like fiscal years), create named ranges for clarity.

Learning Resources

To deepen your understanding of Excel date functions, explore these authoritative resources:

Frequently Asked Questions

Why does Excel think February 29, 1900 existed?

This is a legacy bug from Lotus 1-2-3 that Excel maintained for compatibility. The 1900 date system incorrectly treats 1900 as a leap year, even though it wasn’t (1900 is divisible by 100 but not by 400). The 1904 date system corrects this issue.

How can I calculate the number of weeks between two dates?

Divide the day count by 7 and use appropriate rounding:

=ROUND(DAYS(end_date,start_date)/7,2)  ' decimal weeks
=ROUNDDOWN(DAYS(end_date,start_date)/7,0)  ' full weeks
=CEILING(DAYS(end_date,start_date)/7,1)  ' round up to next week
            

Can I calculate the number of months between dates ignoring the day?

Yes, use DATEDIF with “m” unit, but be aware it counts complete months:

=DATEDIF(start_date, end_date, "m")

For example, between Jan 31 and Feb 1 would return 1 month, while between Jan 31 and Feb 28 would return 0 months.

How do I handle dates before 1900 in Excel?

Excel’s date system doesn’t support dates before 1900 (or 1904). For historical dates:

  • Store as text and convert manually
  • Use a custom VBA function
  • Consider specialized historical date libraries

Why does my date calculation give a different result on Mac vs Windows?

This is almost certainly due to the different default date systems (1900 vs 1904). Check your Excel preferences under:

  • Windows: File > Options > Advanced > “Use 1904 date system”
  • Mac: Excel > Preferences > Calculation > “Use 1904 date system”

Ensure both systems use the same date system for consistent results.

Leave a Reply

Your email address will not be published. Required fields are marked *