Calculating Days Between Dates in Excel
In this article
Excel can calculate the exact number of days between two dates instantly using a simple subtraction formula or a dedicated function, provided the dates are stored as valid date values rather than text. This process works in all modern versions of Excel for Windows, Mac, and the web version.
What You'll Need
- A computer with Microsoft Excel installed (2010 or later is recommended).
- Two dates entered into cells, or the ability to reference cells containing dates.
- Basic knowledge of clicking and typing into spreadsheet cells.
Step-by-Step
- Open your Excel workbook. Navigate to the sheet where you want to perform the calculation. If you are starting from scratch, click on any cell to begin entering your data.
- Enter your start date. Click on the first cell where you want the start date to appear. Type the date in a standard format (e.g.,
1/15/2024or15-Jan-2024) and press Enter. Excel will automatically recognize this as a date and align it to the right. - Enter your end date. Click on the adjacent cell to the right (or wherever you prefer) and type the second date. Again, use a standard format and press Enter. Ensure both cells are clearly labeled if you are working with a large dataset; you can type “Start Date” in the row above and “End Date” in the header row to make it readable.
- Calculate the difference. Click on a third, empty cell where you want the result to appear. Type an equals sign (
=) to start the formula. Click on the cell containing your start date, type a minus sign (-) to indicate subtraction, and then click on the cell containing your end date. Your formula should now look like this:=A2-B2. Press Enter. - Verify the result. Excel will display the number of days between the two dates. For example, if you subtracted
1/15/2024from1/20/2024, the result will be5. If the result is negative, it means the end date is chronologically earlier than the start date. If you see a long number like45231instead of a small one like5, the cells are likely formatted as text (see Troubleshooting). - Format the cell (optional). If the result is a decimal number (e.g.,
5.5), it indicates that your result spans hours and minutes. To display it as a whole number, right-click the cell with the result, select Format Cells, choose Number on the left sidebar, and set the decimal places to 0. Click OK.
Using the DATEDIF Function (Alternative Method)
While subtraction is the most common way to find the difference, Excel includes a legacy function called DATEDIF that can calculate the difference in years, months, or days. This function is useful if you need to know the exact age of an item or person in years and months.
- Click on a cell where you want the result to appear. Type
=DATEDIF(to begin the function. - Select the start date. Click on the cell containing your start date.
- Enter the delimiter. Type a comma (
,). - Select the end date. Click on the cell containing your end date.
- Enter the unit. Type a comma and then the unit code. For days, use
"d". Your formula will look like this:=DATEDIF(A2, B2, "d"). - Close the parenthesis. Type
)and press Enter. The result will be the same as the subtraction method, but this function is more flexible if you need to calculate years or months.
Common Mistakes
- Subtracting text instead of dates. If you type the dates into the formula manually (e.g.,
=DATE(2024, 1, 15)-DATE(2024, 1, 20)) and you are not using the DATE function, or if the cells are formatted as text, Excel will return the #VALUE! error. This happens because Excel cannot perform math on words. Always ensure the cells are recognized as dates. - Forgetting the equals sign. A common error is typing the cell references directly without starting the line with an equals sign (e.g., typing
A2-B2). Excel will treat this as text, and the cell will simply display the text of the formula rather than calculating the number. - Incorrect date formats. In some regions, dates are written with the day first (DD/MM/YYYY) and in others, the month first (MM/DD/YYYY). Excel usually detects this automatically, but if you are seeing strange results, check your regional date settings in the Windows Control Panel or Mac System Preferences. If the format is ambiguous, Excel may misinterpret the year.
Tips
- Use cell references. Always refer to the cells (e.g.,
A2) rather than typing the date numbers directly into the formula (e.g.,1/15/2024). If you need to change the start date later, you can simply type the new date into cell A2, and the result in the calculation cell will update automatically. This makes the spreadsheet dynamic and reusable. - Visualize the data. If you are calculating the days between dates for a project timeline, you can use Excel’s Conditional Formatting feature. Select the result cells, go to the Home tab, click Conditional Formatting, and choose Color Scales. You can then set it to highlight cells that are approaching a deadline (e.g., red for short timeframes) or have passed (e.g., red for negative numbers).
- Working with Today’s Date. To calculate the number of days between a past date and today, you can use the
TODAY()function. For example,=TODAY()-A2will give you the number of days since the date in cell A2. Note that this number will change every time you open or recalculate the workbook, as it always refers to the current system date.
Troubleshooting
If your calculation is not working as expected, follow these steps in order to identify the issue.
The result is a long number (e.g., 45231)
This indicates that Excel is treating your dates as serial numbers rather than date values. In Excel’s internal system, the date 1/1/1900 is serial number 1. If you see a large number, your data is likely stored as text. To fix this, select the column of dates, go to the Data tab, and click Text to Columns. Click Finish on the first two steps, then select Date from the column data format options and select the correct date format (e.g., MDY) to convert the text into real dates.
The result is the #VALUE! error
This error means Excel cannot process the data in one of the cells. Check that both cells are formatted as dates. Go to the Home tab, find the Number group, and click the dropdown menu. Select Date. If the cell still contains the error, try retyping the date manually by deleting the existing text and typing the date again. If the date is imported from another source, it may contain hidden characters that prevent it from being recognized.
The result is negative when it should be positive
This typically happens if the order of the dates in the formula is reversed. Ensure that you are subtracting the earlier date from the later date. You can use the MAX function to ensure a positive result regardless of order: =MAX(A2, B2)-MIN(A2, B2). This formula will always return the absolute difference between the two dates.
Frequently Asked Questions
How do I calculate the number of business days between two dates?
You cannot do this with the basic subtraction method. You must use the NETWORKDAYS function. This function counts only the days from Monday through Friday, excluding weekends. You can also include a list of holidays to exclude them from the count. The syntax is =NETWORKDAYS(start_date, end_date, [holidays]).
Does the order of the dates matter?
Yes, subtraction is not commutative. A2-B2 is not the same as B2-A2. A2-B2 will give you the number of days from the date in A2 up to the date in B2. If A2 is later than B2, the result will be negative. If you need the absolute difference regardless of order, use the ABS function: =ABS(A2-B2).
Can I calculate the difference across different years?
Absolutely. Excel handles dates spanning multiple years seamlessly. The subtraction method works for any two dates within the supported range (January 1, 1900, to December 31, 9999). The function will automatically account for leap years and varying month lengths.
Why does my calculation update every time I open the file?
This happens if you use the TODAY() or NOW() functions. These functions are volatile, meaning they recalculate every time you edit a cell or open the workbook. If you want a static calculation that does not change, type the dates directly into the formula or copy and paste the result as values.
How do I calculate the difference if the dates are in different columns?
You simply reference the cells in different columns. For example, if your start date is in column A and your end date is in column C, your formula would be =A2-C2. The logic remains the same; you are just adding a third column into the equation.