Example 1 – COUNTIF Function to Count Within a Time in Excel
To get the number of shows within a schedule,
Steps:
- Add two new rows in the dataset to input the time and count the number of shows within that time.
We want to get the number of shows that will start within 18:00.
- Put 18:00 on Cell F5.
- Insert the following formula on Cell F6.
=COUNTIF(C5:C9,">="&F4)
- Press Enter to get the result.
Read More: COUNTIF Function to Count Cells That Are Not Equal to Zero
Example 2 – Use of Multiple COUNTIF Functions to Count Within a Time Range
Steps:
- Add new rows in the dataset for start and end times.
- Enter the start and end times.
- Enter the following formula based on the combination of two COUNTIF functions.
=COUNTIF(C5:C9,">"&F4)-COUNTIF(C5:C9,">"&F5)
We have performed a subtraction operation.
Read More: How to Use COUNTIF Function in Excel Greater Than Percentage
Several Alternatives to COUNTIF Function for Time Ranges in Excel
Method 1 – COUNTIFS Function to Count Within Specific Time Range
In this section, we will use the COUNTIFS function to count the number shows within a time range.
We already input the start and end times of movie shows.
Steps:
- Add the formula below in Cell F6.
=COUNTIFS(C5:C9,">"&F4,C5:C9,"<"&F5)
We get no. of shows successfully. In the case of the COUNTIF function, we needed two functions. Using a single COUNTIFS function, we get the same result.
We can also insert the following TIME function.
=COUNTIFS(C5:C9,">"&TIME(17,30,0),C5:C9,"<"&TIME(18,30,0))
Read More: COUNTIF Between Two Cell Values in Excel
Method 2 – Excel SUMPRDUCT Function to Count Between Time Range
Steps:
- Enter the following formula based on the SUMPRODUCT function in Cell F6.
=SUMPRODUCT((C5:C9>=F4)*(C5:C9<=F5))
We will get the no. of shows in the range of 17:30 to 18:30.
Read More: Excel COUNTIF to Count Cells Greater Than 1
Method 3 – Excel SUMIFS Function to Sum Values Between Time Range
Steps:
- We have modified the dataset by adding number of tickets sold. We want to count the number of tickets within a time range.
- Go to Cell F6 and enter the following formula.
=SUMIFS(D5:D9, C5:C9, ">=" & G4, C5:C9, "<=" & G5)
Two movie shows start within this time range and we get the total numbers of tickets sold for those shows.
Read More: How to Use COUNTIF for Non Contiguous Range in Excel
Method 4 – Use of Excel IF Function Between Multiple Time Ranges
The IF function checks whether a condition is met, and returns one value condition is TRUE and another value if FALSE
To find out the no. of shows that will start before 17:30 and after 18:30.
Steps:
- Go to Cell F6 and enter the following formula.
=SUM(IF(C5:C9<F4,1,""),(IF(C5:C9>F5,1,"")))
We get 3 in return. It means a total of 3 shows will start in the given two-time ranges.
Read More: How to Use COUNTIF Function to Calculate Percentage in Excel
How to Use COUNTIF Function in Excel for a Date Greater Than 30 Days
We have a dataset of the name of movies with their release dates. We will use the Excel COUNTIF function to calculate the number of movies released in the last 30 days. We will use the TODAY function to get the present day.
Steps:
- Enter the following formula in Cell C11.
=COUNTIF(C5:C9,">"&TODAY()-30)
We will get the number of movies released in the last 30 days. We applied the COUNTIF function with multiple criteria with date ranges.
Read More: How to Compare Two Columns Using COUNTIF Function
Download Practice Workbook
Related Articles
- How to Use COUNTIF Function with Array Criteria in Excel
- How to Calculate Frequency Using COUNTIF Function in Excel
<< Go Back to Excel COUNTIF Function | Excel Functions | Learn Excel
Get FREE Advanced Excel Exercises with Solutions!