How to use the DAYS function
What is the DAYS function?
The DAYS function calculates an integer that represents the number of days between two dates.
There is, actually, an easier way to calculate the number of days between two dates. Simply subtract C3 by B3 like this: = C3-B3 and you will get the number of days.
The DATEDIF function is also able to calculate the number of days between two dates.
Table of Contents
1. Introduction
What are dates in Excel?
Dates are stored numerically but formatted to display in human-readable date/time formats, this enables Excel to do work with dates in calculations.
For example, dates are stored as sequential serial numbers with 1 being January 1, 1900 by default. The integer part (whole number) represents the date the decimal part represents the time.
This allows dates to easily be formatted to display in many date/time formats like mm/dd/yyyy, dd/mm/yyyy and so on and still be part of calculations as long as the date is stored numerically in a cell.
You can try this yourself, type 10000 in a cell, press CTRL + 1 and change the cell's formatting to date, press with left mouse button on OK. The cell now shows 5/18/1927.
Related functions
Excel Function | Description |
---|---|
DAY(date) | Returns the day of the month (1-31) |
DAYS(end_date, start_date) | Returns the number of days between two dates |
NETWORKDAYS(start_date, end_date) | Returns the number of workdays between two dates |
DATEDIF(start_date, end_date, unit) | Returns the time between two dates in specified units like years, monts, etc |
EDATE(start_date, months) | Returns the date that is the indicated number of months before or after start_date |
EOMONTH(start_date, months) | Returns the last day of the month before or after start_date by months |
NETWORKDAYS.INTL(start_date, end_date, weekend) | Returns workdays between dates with custom weekend parameters |
WORKDAY(start_date, days) | Returns a date days away from the start_date, skipping weekends |
2. Syntax
DAYS(end_date, start_date)
end_date | Required. The end date of the date range you want to calculate. |
start_date | Required. The start date of the date range you want to calculate. |
3. Example 1
This example shows the DAYS function in cell D3, in the image above, calculating the difference in days between the specified cells C3 and B3.
Formula in cell D3:
The DAYS function calculates 1 day between 1/1/2030 and 1/2/2030. Why, you may wonder? There are two days in that date range? It depends how you calculate. 1/1/2030 is 47484 and 1/2/2030 is 47485. 47485 - 47484 equals 1.
This is because if you calculate the end date inclusive or not. If you want to include the end date in the calculation then use this:
Formula in cell D3:
4. Example 2
You are the project manager for a new product launch, and you have identified the following milestones:
- Project Kickoff - January 10, 2026
- Design Completion - February 20, 2026
- Prototype Development - April 1, 2026
- Testing and Quality Assurance - May 15, 2026
- Launch Date - June 30, 2026
Use the DAYS function in Excel to calculate the number of days between each milestone. For example,
- How many days are between the Project Kickoff and Design Completion?
- How many days are between Design Completion and Prototype Development?
The image above shows a spreadsheet that lets you select two milestones and calculate the number of days between the given milestones.
Cell B10 contains a drop down list that expands when you select the cell. It allows you to select the specified milestones in cells B3:B7 using the drop down list. Cell C10 also contains a drop down list so you can pick another milestone. The formula in cell C13 uses these milestones to get the correct corresponding dates and then calculate the number of days between.
Formula in cell C13:
Cell B10 contains Project Kickoff and C10 contains Design Completion, the number of days between these milestones are 46. Here is a breakdown of the formula:
- C3:C7 is a range of cells that contains dates.
- B3:B7 is a range of cells that contains milestone names.
- C10 and B10 are cells that contain specific values that are used to filter the data.
The formula is using the FILTER function to select the dates from C3:C7 that correspond to the values in B3:B7 that match the values in C10 and B10.
- FILTER(C3:C7,B3:B7=C10) selects the dates from C3:C7 where the corresponding value in B3:B7 is equal to the value in C10.
- FILTER(C3:C7,B3:B7=B10) selects the dates from C3:C7 where the corresponding value in B3:B7 is equal to the value in B10.
- The DAYS function then calculates the number of days between the two dates that are returned by the FILTER functions.
This formula can be used to calculate the number of days between two specific milestones where the milestones are identified by their names in column B, and the dates are in column C. The values in cells C10 and B10 can be used to select the specific milestones to calculate the days between.
For example, if C10 contains the value "Design Completion" and B10 contains the value "Prototype Development", the formula would calculate the number of days between the Design Completion date and the Prototype Development date.
5. DAYS function tips and tricks
Why are dates sometimes stored as text in Excel?
Excel tries to identify values as text, numbers, Boolean values, dates, and time automatically but may fail in rare occasions. This may happen when you import data from the internet, databases, text files, and other sources. You can convert the dates to Excel dates if you like but it can be a tedious and time consuming task.
There is no need to convert text dates to Excel dates, the DAYS function handles text dates properly.
6. DAYS function not working
The image above shows two dates containing a dot as a delimiting character, this makes Excel return an error.
The DAYS function returns #VALUE! error if a date is not recognized, here is a formula to fix this problem: DATEVALUE function
6.1 Troubleshooting the error value
When you encounter an error value in a cell a warning symbol appears, displayed in the image above. Press with mouse on it to see a pop-up menu that lets you get more information about the error.
- The first line describes the error if you press with left mouse button on it.
- The second line opens a pane that explains the error in greater detail.
- The third line takes you to the "Evaluate Formula" tool, a dialog box appears allowing you to examine the formula in greater detail.
- This line lets you ignore the error value meaning the warning icon disappears, however, the error is still in the cell.
- The fifth line lets you edit the formula in the Formula bar.
- The sixth line opens the Excel settings so you can adjust the Error Checking Options.
Here are a few of the most common Excel errors you may encounter.
#NULL error - This error occurs most often if you by mistake use a space character in a formula where it shouldn't be. Excel interprets a space character as an intersection operator. If the ranges don't intersect an #NULL error is returned. The #NULL! error occurs when a formula attempts to calculate the intersection of two ranges that do not actually intersect. This can happen when the wrong range operator is used in the formula, or when the intersection operator (represented by a space character) is used between two ranges that do not overlap. To fix this error double check that the ranges referenced in the formula that use the intersection operator actually have cells in common.
#SPILL error - The #SPILL! error occurs only in version Excel 365 and is caused by a dynamic array being to large, meaning there are cells below and/or to the right that are not empty. This prevents the dynamic array formula expanding into new empty cells.
#DIV/0 error - This error happens if you try to divide a number by 0 (zero) or a value that equates to zero which is not possible mathematically.
#VALUE error - The #VALUE error occurs when a formula has a value that is of the wrong data type. Such as text where a number is expected or when dates are evaluated as text.
#REF error - The #REF error happens when a cell reference is invalid. This can happen if a cell is deleted that is referenced by a formula.
#NAME error - The #NAME error happens if you misspelled a function or a named range.
#NUM error - The #NUM error shows up when you try to use invalid numeric values in formulas, like square root of a negative number.
#N/A error - The #N/A error happens when a value is not available for a formula or found in a given cell range, for example in the VLOOKUP or MATCH functions.
#GETTING_DATA error - The #GETTING_DATA error shows while external sources are loading, this can indicate a delay in fetching the data or that the external source is unavailable right now.
6.2 The formula returns an unexpected value
To understand why a formula returns an unexpected value we need to examine the calculations steps in detail. Luckily, Excel has a tool that is really handy in these situations. Here is how to troubleshoot a formula:
- Select the cell containing the formula you want to examine in detail.
- Go to tab “Formulas” on the ribbon.
- Press with left mouse button on "Evaluate Formula" button. A dialog box appears.
The formula appears in a white field inside the dialog box. Underlined expressions are calculations being processed in the next step. The italicized expression is the most recent result. The buttons at the bottom of the dialog box allows you to evaluate the formula in smaller calculations which you control. - Press with left mouse button on the "Evaluate" button located at the bottom of the dialog box to process the underlined expression.
- Repeat pressing the "Evaluate" button until you have seen all calculations step by step. This allows you to examine the formula in greater detail and hopefully find the culprit.
- Press "Close" button to dismiss the dialog box.
There is also another way to debug formulas using the function key F9. F9 is especially useful if you have a feeling that a specific part of the formula is the issue, this makes it faster than the "Evaluate Formula" tool since you don't need to go through all calculations to find the issue..
- Enter Edit mode: Double-press with left mouse button on the cell or press F2 to enter Edit mode for the formula.
- Select part of the formula: Highlight the specific part of the formula you want to evaluate. You can select and evaluate any part of the formula that could work as a standalone formula.
- Press F9: This will calculate and display the result of just that selected portion.
- Evaluate step-by-step: You can select and evaluate different parts of the formula to see intermediate results.
- Check for errors: This allows you to pinpoint which part of a complex formula may be causing an error.
The image above shows cell reference D3 converted to hard-coded value using the F9 key. The DAYS function requires Excel dates which is not the case in this example. We have found what is wrong with the formula.
Tips!
- View actual values: Selecting a cell reference and pressing F9 will show the actual values in those cells.
- Exit safely: Press Esc to exit Edit mode without changing the formula. Don't press Enter, as that would replace the formula part with the calculated value.
- Full recalculation: Pressing F9 outside of Edit mode will recalculate all formulas in the workbook.
Remember to be careful not to accidentally overwrite parts of your formula when using F9. Always exit with Esc rather than Enter to preserve the original formula. However, if you make a mistake overwriting the formula it is not the end of the world. You can “undo” the action by pressing keyboard shortcut keys CTRL + z or pressing the “Undo” button
6.3 Other errors
Floating-point arithmetic may give inaccurate results in Excel - Article
Floating-point errors are usually very small, often beyond the 15th decimal place, and in most cases don't affect calculations significantly.
'DAYS' function examples
The following article has a formula that contains the DAYS function.
Functions in 'Date and Time' category
The DAYS function function is one of 22 functions in the 'Date and Time' category.
How to comment
How to add a formula to your comment
<code>Insert your formula here.</code>
Convert less than and larger than signs
Use html character entities instead of less than and larger than signs.
< becomes < and > becomes >
How to add VBA code to your comment
[vb 1="vbnet" language=","]
Put your VBA code here.
[/vb]
How to add a picture to your comment:
Upload picture to postimage.org or imgur
Paste image link to your comment.
Contact Oscar
You can contact me through this contact form