Count Excel Times Across Midnight with COUNTIFS
Question details
Count records whose times fall within a range that crosses midnight.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- A user needs to count entries from 10:00 PM through the period before 4:00 AM.
- Observed behavior
- Applying both time-only conditions to the same range with COUNTIFS uses AND logic and returns zero because a time cannot be both at or after 10:00 PM and before 4:00 AM.
Check that the cells contain actual Excel time or date-time values rather than text. Identify whether the range contains times only or full date-time values, because each requires a different formula.
Add two COUNTIFS results for time-only values
Use this formula when the range contains times without dates.
The overnight window consists of two periods: 10:00 PM to midnight and midnight to before 4:00 AM. Adding their counts provides the OR logic needed for the full window.
Click an empty cell where you want to display the count.
Type =COUNTIFS(A2:A100,">="&TIME(22,0,0))+COUNTIFS(A2:A100,"<"&TIME(4,0,0)) and press Enter. Replace both instances of A2:A100 with your time-only range.
Compare the result with your source cells: 10:00 PM is included, while 4:00 AM is excluded.

Count full date-time values using overnight boundaries
Use this method to count events for a specific overnight period when each record includes a date and time.
Count overnight records in WPS Spreadsheets
Use COUNTIFS in WPS Spreadsheets to add two time-only counts or apply full date-time boundaries to a specific overnight period.
- 1. Open your spreadsheet: Open WPS Spreadsheets and choose File > Open to select your workbook.
- 2. Check the source values: Select the time column and check whether its cells contain time-only values or full dates and times.
- 3. Enter an overnight count: For time-only values in A2:A100, click an empty cell and enter =COUNTIFS(A2:A100,">="&TIME(22,0,0))+COUNTIFS(A2:A100,"<"&TIME(4,0,0)).
- 4. Review the result: Press Enter and compare the count with the source rows, noting that 10:00 PM is included and 4:00 AM is excluded.

Frequently Asked Questions
Why does COUNTIFS return zero for an overnight time range?
COUNTIFS combines criteria with AND. A time-only value cannot be both at or after 10:00 PM and before 4:00 AM, so count the two periods separately and add the results.
How do I include exactly 4:00 AM in the count?
For time-only values, change the second criterion from "<"&TIME(4,0,0) to "<="&TIME(4,0,0). For full date-time values, make the same change to the end-boundary criterion.
Can I count events for one specific overnight shift?
Yes. For full date-time values, put the shift's starting date in D2 and use boundaries of D2+TIME(22,0,0) and D2+1+TIME(4,0,0) in COUNTIFS.
What if my times are stored as text?
Convert the entries to actual time values before counting. For a recognized time string in A2, enter =TIMEVALUE(A2) in another cell, fill the formula down, and use the resulting values in your count.




