Count records between two dates in excel
Someone googled "Count records between date range" and landed on my website. I realize I have not covered this problem.
Yellow cells are user input cells.
How do I automatically count records in a specific date range?
Array formula in cell D3:
This is an array formula so make sure you press Ctrl + Shift + Enter.
Alternative array formula in cell D3:
If you want to count the start date and end date also, try this formula:
Alternative formula:
Explaining alternative formula in cell D3
=SUMPRODUCT(--($A$2:$A$10<=$D$2),--($A$2:$A$10>=$D$1))
Step 1 - Create a boolean array with matching dates to the first criterion
=SUMPRODUCT(--($A$2:$A$10<=$D$2),--($A$2:$A$10>=$D$1))
--($A$2:$A$10<=$D$2)
becomes
--({39448;39450;39448;39474;39459;39473;39453;39452;39463}<=39463)
becomes
--({39448;39450;39448;39474;39459;39473;39453;39452;39463}<=39463)
becomes
--({TRUE;TRUE;TRUE;FALSE;TRUE;FALSE;TRUE;TRUE;TRUE})
becomes
{1;1;1;0;1;0;1;1;1}
Step 2 - Create a boolean array with matching dates to the second criterion
=SUMPRODUCT(--($A$2:$A$10<=$D$2),--($A$2:$A$10>=$D$1))
--($A$2:$A$10>=$D$1)
becomes
--({39448;39450;39448;39474;39459;39473;39453;39452;39463}>=39452)
becomes
--({FALSE;FALSE;FALSE;TRUE;TRUE;TRUE;TRUE;TRUE;TRUE})
becomes
{0;0;0;1;1;1;1;1;1}
Step 3 - All together
=SUMPRODUCT(--($A$2:$A$10<=$D$2),--($A$2:$A$10>=$D$1))
becomes
=SUMPRODUCT({1;1;1;0;1;0;1;1;1},{0;0;0;1;1;1;1;1;1})
becomes
=SUMPRODUCT({0;0;0;0;1;0;1;1;1}) returns 4.
Download excel sample file for this tutorial.
count-records-between-two-dates-in-excel
(Excel 97-2003 Workbook *.xls)
Functions in this article:
SUM(number1,[number2],)
Adds all the numbers in a range of cells
IF(logical_test;[value_if:true];[value_if_false])
Checks whether a condition is met, and returns one value if TRUE, and another value if FALSE
This blog article is one out of four articles on the same subject.
- Most common value between two dates in excel
- Count records between two dates in excel
- Count unique distinct records in a date range
- Count unique records by date







May 5th, 2009 at 7:05 pm
This did a great job of giving me what I needed, with a minor tweak in that I took out the $ in $D$2 and $D$1 and replaced with D2 & D3, respectively.
In case someone might ask why, it easily replicates the formula multiple times by copy/paste methods. Otherwise, copying and pasting into the next cell to total the difference between the next two dates on a long list of dates will simply copy the same exact formula 30 timess. The $ make the cell range entered constant, ignoring Excel's internal mechanisms that would otherwise tell the formula to automatically adjust to the new formula location (d3&d2, d4&d3, d5&d4, etc.). You still want to use the ctrl+enter, though. I had about 300 rows with dates ranging over two months to work with.
Thanks so much!
May 5th, 2009 at 9:08 pm
Thanks for your comment!
September 8th, 2010 at 11:24 am
Great job, I've seen some posts regarding this this subject but your SUMPRODUCT solution is the more elegant and versatile I've found!
Thumbs up and thanks!
September 28th, 2010 at 3:45 pm
Any chance this would work with multiple parameters.
I need to count how many times JA appears in a given period 1-Sep-10 and 10-Sep-10
A B
1 JA 2-Sep-10
2 SH 11-Sep-10
3 JA 3-Sep-10
I can't seem to link CountIf(A1:A3,"JA") and the Sum(If) part
any help greatly appreciated.
September 28th, 2010 at 9:43 pm
Sam,
read this post: Count records between two dates with multiple parameters in excel
October 15th, 2010 at 11:08 am
thanks man, worked a treat
November 11th, 2010 at 8:52 pm
I can't seem to take this work. I am using the SUMPRODUCT formula. The only difference is that the dates to count are on another sheet within the workbook, but I would doubt that would be the issue. I keep getting the #NUM! error, but I have double verified that all reference cells are formated as dates. Please help.
November 11th, 2010 at 9:54 pm
Excel stores dates as a number representing the number of days since 1900-Jan-0 This is called a serial date, or serial date-time.
Source: http://www.cpearson.com/excel/datetime.htm
Are all referenced cell values serial dates?
November 11th, 2010 at 10:18 pm
How can i tell. I did read the article and played with the 1904 system indicator under options, but none of that made the formula work.
November 12th, 2010 at 11:37 am
Marina,
Select a date cell.
Press Ctrl + 1.
Select "Category:" General.
If sample data shows you a number like 40494 (today) then you know it is a serial date.
December 22nd, 2010 at 5:56 am
Good work guys, but I require little different solution.
In A column, there are dates in mmddyyy format and in B column, there are two variables uses either "PASS" or "FIAIL". All I want to do is to count the "PASS" in individual month range.
Can someone help me in it. I am able to count days of month from the column A but can not link it with Column B.
Regards,
Johny
December 22nd, 2010 at 9:23 am
Janib Soomro,
Read this post: Count matching cells in date range in excel
September 30th, 2011 at 6:14 am
thanks, I need to count in a list the interval between the same value, example list, 1-2-3-1-4-5-1-6-7-8-9-7-8-1 so the answer must be for the value 1 the spaces are 2,2,6. thank you
October 6th, 2011 at 9:28 pm
jeyner,
read this post:
Excel: List intervals between two values
October 26th, 2011 at 9:49 pm
how do i count cells to determine how many cells occured on jan 2, 2011 from 2 am and 6 am.. which is housed in one of my columns in my excel workbook.