Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 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.

Counting Dates in a Range

Written by Allen Wyatt (last updated February 13, 2021)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365


2

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:

=COUNTIFS(B1:B101,">="&E1,B1:B101,"<="&E2)

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:

=IF(AND(B1>=E$1,B1<=E$2),1,0)

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:

=SUM(C1:C101)

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.)

=COUNT(IF((B1:B101>$E$1)*(B1:B101<$E$2),B1:B101))

If you prefer to not use an array formula, you can use the following standard COUNTIF-based formula in E4:

=-COUNT(B1:B101)+COUNTIF(B1:B101,">"&E1)+COUNTIF(B1:B101,"<"&E2)

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:

  1. Place a blank row at the top of your data, which pushes everything down by one cell.
  2. With your dates now in cells B2:B102, select cell B1 and place a label, such as MyDates, in the cell.
  3. Format cell B1 as desired.
  4. Select the entire range, including the label (cells B1:B102).
  5. Using the Name Box (just above the row headers and to the left of the column headers), define a name for the range. The name should be the same as the name you used in step 2 (MyDates).
  6. In cells D1 and E1, place your label name (MyDates).
  7. In cell D2 enter a greater-than sign and the lower date for your range of dates, as in ">4/1/2002" (without the quote marks).
  8. In cell E2 enter a less-than sign and the upper date for your range of dates, as in "<6/1/2002" (without the quote marks).
  9. In cell E4, enter the following formula:
     =DCOUNT(MyDates,1,D1:E2)

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 Microsoft 365. You can find a version of this tip for the older menu interface of Excel here: Counting Dates in a Range.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Large Toolbar Buttons

Do you wish that the buttons on your Excel toolbars were easier to see and use? The answer could be to turn on the large ...

Discover More

Turning Off AutoFill

AutoFill is a great editing tool that comes in particularly handy when you are first creating a worksheet. You may, at ...

Discover More

Saving Information in a Text File

The VBA programming language provided with Excel allows you to create and modify text files quite easily. Here's how to ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!

More ExcelTips (ribbon)

Calculating Months of Tenure

Need to know the number of months between two dates? It's easy to figure out if you use the DATEDIF function.

Discover More

Deciphering a Coded Date

It is no secret that Excel allows you to work with dates in your worksheets. Getting your information into a format that ...

Discover More

Calculating Differences in Months using Non-Standard Date Values

Dates can be entered into a worksheet in any number of unique or novel ways. Working with those dates can be a challenge, ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 8 + 7?

2021-02-15 15:37:31

David Bonin

= SUMPRODUCT(( B1:B101 >= $E$1) * ( B1:B101 <= $E$2 ))
<or>
= SUMPRODUCT( - - ( B1:B101 >= $E$1), - - ( B1:B101 <= $E$2 ))
Either way, this is entered as a normal (non-array) formula.

The first formula creates two internal arrays of TRUE and FALSE values and multiplies each pair of elements together, which is equivalent to a Boolean AND. Boolean math returns a similar internal array 1's and 0's corresponding to whether each date in B1:B101 is between E1 and E2. SUMPRODUCT() sums that all up and gives the count you want.
The second formula is very similar except the two internal arrays of TRUE and FALSE values are converted by the double negation "- -" to 1's and 0's. SUMPRODUCT() then multiplies each pair of elements in the internal arrays and sums that up to give you the count you want.


2021-02-14 18:16:48

Nathan A Buchheit

Tried it for a very long column (2000) but it did not count every one that fit the criteria. Missed 4 out of the 15 that were present. Any idea why?


This Site

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.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.