Excel Days Between Dates Calculator
Calculate the exact number of days between two dates with Excel formulas. Includes weekend and holiday exclusion options.
=DATEDIF()
Comprehensive Guide: Excel Formulas to Calculate Days Between Dates
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 explore all the methods available in Excel to calculate date differences, including handling weekends, holidays, and various edge cases.
Basic Date Difference Calculation
The simplest way to calculate days between dates in Excel is by using basic subtraction:
- Enter your start date in cell A1 (e.g., 01/15/2023)
- Enter your end date in cell B1 (e.g., 02/20/2023)
- In cell C1, enter the formula:
=B1-A1
Excel will automatically return the number of days between the two dates. By default, Excel stores dates as serial numbers (with January 1, 1900 as day 1), so subtracting one date from another gives you the difference in days.
The DATEDIF Function
For more control over date calculations, Excel provides the DATEDIF function (Date DIFFerence). This function can calculate differences in days, months, or years:
Syntax: =DATEDIF(start_date, end_date, unit)
Where unit can be:
"d"– Complete days between dates"m"– Complete months between dates"y"– Complete years between dates"ym"– Months excluding years"yd"– Days excluding years"md"– Days excluding months and years
Example: =DATEDIF("1/15/2023", "2/20/2023", "d") returns 36 days
| Unit | Description | Example (1/15/2023 to 2/20/2023) | Result |
|---|---|---|---|
| “d” | Complete days between dates | =DATEDIF(“1/15/2023”, “2/20/2023”, “d”) | 36 |
| “m” | Complete months between dates | =DATEDIF(“1/15/2023”, “2/20/2023”, “m”) | 1 |
| “y” | Complete years between dates | =DATEDIF(“1/15/2023”, “2/20/2023”, “y”) | 0 |
| “ym” | td>Months excluding years=DATEDIF(“1/15/2023”, “2/20/2023”, “ym”) | 1 | |
| “yd” | Days excluding years | =DATEDIF(“1/15/2023”, “2/20/2023”, “yd”) | 36 |
| “md” | Days excluding months and years | =DATEDIF(“1/15/2023”, “2/20/2023”, “md”) | 5 |
Calculating Weekdays (Excluding Weekends)
To calculate only weekdays (Monday through Friday) between two dates, you can use the NETWORKDAYS function:
Syntax: =NETWORKDAYS(start_date, end_date, [holidays])
The optional holidays parameter allows you to specify a range of dates to exclude (like company holidays).
Example: =NETWORKDAYS("1/15/2023", "2/20/2023") returns 26 weekdays
If you need to exclude specific holidays, you can reference a range containing those dates:
=NETWORKDAYS("1/15/2023", "2/20/2023", A2:A5) where A2:A5 contains holiday dates
Calculating Business Days with Custom Weekends
For organizations that have non-standard weekends (like Friday-Saturday in some Middle Eastern countries), you can use the NETWORKDAYS.INTL function:
Syntax: =NETWORKDAYS.INTL(start_date, end_date, [weekend], [holidays])
The weekend parameter specifies which days are weekends using a weekend number or string:
| Weekend Number | Weekend Days | String Alternative |
|---|---|---|
| 1 or omitted | Saturday, Sunday | “0000011” |
| 2 | Sunday, Monday | “1000001” |
| 3 | Monday, Tuesday | “1100000” |
| 4 | Tuesday, Wednesday | “0110000” |
| 5 | Wednesday, Thursday | “0011000” |
| 6 | Thursday, Friday | “0001100” |
| 7 | Friday, Saturday | “0000110” |
| 11 | Sunday only | “1000000” |
| 12 | Monday only | “0100000” |
| 13 | Tuesday only | “0010000” |
| 14 | Wednesday only | “0001000” |
| 15 | Thursday only | “0000100” |
| 16 | Friday only | “0000010” |
| 17 | Saturday only | “0000001” |
Example: For a Friday-Saturday weekend (common in some Middle Eastern countries):
=NETWORKDAYS.INTL("1/15/2023", "2/20/2023", 7) or =NETWORKDAYS.INTL("1/15/2023", "2/20/2023", "0000110")
Handling Leap Years
Excel automatically accounts for leap years in its date calculations. A leap year occurs:
- Every year divisible by 4
- Except for years divisible by 100, unless
- The year is also divisible by 400
For example, the year 2000 was a leap year (divisible by 400), but 1900 was not (divisible by 100 but not by 400).
To verify if a year is a leap year in Excel, you can use this formula:
=OR(MOD(year,400)=0,AND(MOD(year,4)=0,MOD(year,100)<>0))
Where year is the year you want to check (e.g., 2024). This returns TRUE for leap years and FALSE for non-leap years.
Calculating Age in Years, Months, and Days
To calculate someone’s age in years, months, and days, you can combine several functions:
=DATEDIF(birth_date, TODAY(), "y") & " years, " & DATEDIF(birth_date, TODAY(), "ym") & " months, " & DATEDIF(birth_date, TODAY(), "md") & " days"
This formula:
- Calculates complete years with
"y" - Calculates remaining months with
"ym" - Calculates remaining days with
"md" - Combines them into a single text string
Working with Dates Before 1900
Excel’s date system starts on January 1, 1900 (which is stored as serial number 1). For dates before 1900, you’ll need to:
- Store them as text
- Use text functions to manipulate them
- Convert to proper dates when needed using
DATEVALUE(though this won’t work for pre-1900 dates)
For historical date calculations, you might need to:
- Use a custom VBA function
- Implement the proleptic Gregorian calendar calculations manually
- Use a third-party add-in designed for historical dates
Time Zone Considerations
Excel doesn’t natively handle time zones in date calculations. All dates are treated as local to the system’s time zone settings. For international date calculations:
- Convert all dates to UTC before calculations
- Use the
=NOW()function carefully as it returns the current date and time according to the system clock - For critical applications, consider using Power Query to handle time zone conversions
The TODAY() function returns the current date based on the system clock, while NOW() returns both date and time. Neither accounts for time zones in their calculations.
Common Errors and Troubleshooting
When working with date calculations in Excel, you might encounter these common issues:
- #VALUE! error: Typically occurs when one of your date arguments isn’t recognized as a valid date. Check that:
- Cells are formatted as dates
- Dates are entered correctly (Excel might interpret 01/02/2023 as January 2 or February 1 depending on system settings)
- There are no hidden characters in your date cells
- Negative results: This happens when your end date is earlier than your start date. Either:
- Swap the dates
- Use
ABS()to get the absolute value:=ABS(end_date-start_date)
- Incorrect weekend calculations: If
NETWORKDAYSisn’t working as expected:- Verify your weekend parameters
- Check that holiday dates are in a valid range
- Ensure dates are actual Excel dates, not text
- 1900 vs 1904 date system: Excel for Windows uses 1900 date system (1 = 1/1/1900), while Excel for Mac historically used 1904 date system (0 = 1/2/1904). This can cause date differences of 1462 days. To check your system:
- Go to File > Options > Advanced
- Under “When calculating this workbook”, check the date system
- Convert between systems with:
=date+1462(1900 to 1904) or=date-1462(1904 to 1900)
Advanced Techniques
For more complex date calculations, consider these advanced techniques:
Array Formulas for Custom Weekends
Before NETWORKDAYS.INTL was introduced, users created array formulas to handle custom weekends. While no longer necessary for simple cases, understanding this approach can help with more complex scenarios:
=SUM(IF(WEEKDAY(ROW(INDIRECT(start_date&":"&end_date)))={2,3,4,5,6},1,0))
This counts weekdays between dates (Monday-Friday) using an array formula.
Dynamic Date Ranges
For reports that need to show data for “last 30 days” or “current month to date”, use these dynamic formulas:
- Last 30 days:
=TODAY()-30as your start date - Current month to date:
=EOMONTH(TODAY(),-1)+1as your start date - Previous month:
=EOMONTH(TODAY(),-1)+1to=EOMONTH(TODAY(),0) - Current quarter to date:
=DATE(YEAR(TODAY()),CHOOSER(MONTH(TODAY()),1,1,1,4,4,4,7,7,7,10,10,10),1)
Date Validation
To ensure cells contain valid dates, use data validation:
- Select the cells to validate
- Go to Data > Data Validation
- Set “Allow” to “Date”
- Set appropriate start/end dates if needed
- Add an input message and error alert
For more complex validation (like ensuring end date is after start date), use custom formulas in data validation.
Real-World Applications
Date calculations have numerous practical applications across industries:
Project Management
- Calculating project durations
- Creating Gantt charts
- Tracking milestones and deadlines
- Resource allocation planning
Human Resources
- Calculating employee tenure
- Tracking probation periods
- Vacation accrual calculations
- Benefits eligibility determination
Finance and Accounting
- Interest calculations
- Depreciation schedules
- Payment term tracking
- Fiscal period reporting
Manufacturing and Logistics
- Lead time calculations
- Inventory turnover analysis
- Delivery schedule planning
- Warranty period tracking
Best Practices for Date Calculations
- Consistent date formats: Ensure all dates in your workbook use the same format to avoid confusion and errors.
- Document your formulas: Add comments to complex date calculations to explain their purpose and logic.
- Use named ranges: For frequently used dates (like company holidays), define named ranges for easier reference.
- Handle errors gracefully: Use
IFERRORto provide meaningful messages when date calculations fail. - Test edge cases: Always test your date calculations with:
- Dates spanning month/year boundaries
- Leap days (February 29)
- Date ranges that include weekends and holidays
- Very large date ranges (decades or centuries)
- Consider time zones for international data: If working with dates from multiple time zones, document which time zone each date represents.
- Use helper columns: For complex calculations, break them down into intermediate steps in helper columns for easier debugging.
- Protect critical dates: Lock cells containing important dates to prevent accidental changes.
Excel vs Other Tools
While Excel is powerful for date calculations, other tools have different strengths:
| Tool | Strengths | Weaknesses | Best For |
|---|---|---|---|
| Excel |
|
|
|
| Google Sheets |
|
|
|
| Python (Pandas) |
|
|
|
| SQL |
|
|
|
| R |
|
|
|
Learning Resources
To deepen your understanding of Excel date functions, consider these authoritative resources:
Frequently Asked Questions
Why does Excel show ###### in my date cells?
This typically happens when:
- The column isn’t wide enough to display the entire date
- The cell contains a negative date (before Excel’s date system starts)
- The cell format is incorrect for the value it contains
Solution: Widen the column or check the cell format (should be Date).
How do I calculate the number of months between two dates?
Use DATEDIF with the “m” unit:
=DATEDIF(start_date, end_date, "m")
For partial months, you might want to combine with day calculations.
Can I calculate the number of specific weekdays between dates?
Yes, you can use a combination of functions. For example, to count Mondays:
=SUMPRODUCT(--(WEEKDAY(ROW(INDIRECT(start_date&":"&end_date)))=2))
This is an array formula that checks each day in the range for Monday (weekday number 2).
Why is my NETWORKDAYS calculation off by one day?
This usually happens because:
- Your start or end date falls on a weekend or holiday
- You’re not accounting for the inclusive/exclusive nature of the dates
- There’s a time component to your dates affecting the calculation
Solution: Check if your dates are actual dates (not text), verify your weekend parameters, and ensure holiday dates are correct.
How do I handle dates in different time zones?
Excel doesn’t natively support time zones. Best practices include:
- Convert all dates to UTC before calculations
- Document which time zone each date represents
- Use helper columns to show both local and UTC times
- For critical applications, consider using Power Query for time zone conversions
Conclusion
Mastering date calculations in Excel opens up powerful possibilities for data analysis, project management, financial modeling, and more. From simple day counts with basic subtraction to complex business day calculations with custom weekends and holidays, Excel provides a robust set of tools for working with dates.
Remember these key points:
- Excel stores dates as serial numbers, enabling mathematical operations
DATEDIFoffers flexible date difference calculationsNETWORKDAYSandNETWORKDAYS.INTLhandle business day calculations- Always test your formulas with edge cases like leap days and month/year boundaries
- Document complex calculations for future reference
- Consider time zones when working with international data
As you become more comfortable with Excel’s date functions, you’ll find increasingly creative ways to apply them to your specific needs. Whether you’re tracking project timelines, analyzing financial periods, or managing employee schedules, accurate date calculations are fundamental to effective data analysis in Excel.