Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, and Excel in Office 365. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Counting Dates in a Range.
by Allen Wyatt
(last updated February 13, 2021)
If you have a range of cells that are filled with random, non-sorted dates, you may want to figure out how many of those dates fall between a start date and an end date. For instance, if B1:B101 contains the random dates, cell E1 contains the start date, and cell E2 contains the end date, you may want to know what type of formula you can use in cell E4 to return the number of dates in B1:B101 that fall between E1 and E2.
There are actually several different ways you can arrive at a solution. The first, of course, would be to use the COUNTIFS function, in this manner:
The formula returns a count of dates in the range, just as you want. The problem with COUNTIFS, though, is that it is a relatively new addition to Excel, first becoming available in Excel 2013. If you are using an older version of the program (or if someone else using your workbook is using an older version), then you need a different solution. The balance of the approaches in this tip will work with all versions of Excel, but are particularly appropriate for the older (pre-2013) versions.
The first approach would be to simply add a formula in each cell to the right of the dates in column B, and have that formula return a 1 if the date is between E1 and E2, or a 0 if not. You could then sum the column to get the desired count. You would use the following formula in each cell to the right of the dates:
This particular formula goes into cell C1, and can then be copied down to cells C2 through C101. Then, in cell E4, all you would need to do is use the following formula:
The drawback to this, of course, is that the additional values in C1:C101 can play havoc with the appearance of a carefully crafted worksheet. Fortunately there are ways to find the proper result without the need to use an intermediate value.
One way is to use an array formula. The following formula, placed in cell E4, will do the trick. All you need to do is remember to enter the formula using Shift+Ctrl+Enter. (This signifies to Excel that you are entering an array formula.)
If you prefer to not use an array formula, you can use the following standard COUNTIF-based formula in E4:
When you enter this formula, Excel will assume that you are returning a date value, and will therefore helpfully format the cell as a date. All you need to do to correct this is to use Format | Cell to format the cell using something besides a date format, such as General.
The formula works by counting all dates that are after the early date plus all dates that are before the late date. This essentially counts all dates once and double-counts the desired selection. By subtracting the number of dates in the range (at the beginning of the formula), the formula effectively eliminates all but the desired result.
If you prefer, you can also use the DCOUNT function to return the desired count. This, however, is just a bit more involved. Unlike the earlier solutions, DCOUNT relies on the use of named ranges. Follow these steps:
The DCOUNT function uses the criteria you specified in D1:E2 to examine the data range defined as MyDates and return the count of cells that meets those criteria.
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (11839) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Office 365. You can find a version of this tip for the older menu interface of Excel here: Counting Dates in a Range.
Excel Smarts for Beginners! Featuring the friendly and trusted For Dummies style, this popular guide shows beginners how to get up and running with Excel while also helping more experienced users get comfortable with the newest features. Check out Excel 2013 For Dummies today!
Want to add an ordinal suffix to a number, as in 2nd, 3rd, or 4th? Excel doesn't provide a way to do it automatically, ...Discover More
Some industries (such as the military) have special formatting that they use to represent dates. Here is one such format ...Discover More
Many businesses need to know when the last business day of the month occurs. This tip discusses several ways you can ...Discover More
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.