Calculation Issues

Count Excel Times Across Midnight with COUNTIFS

Aamir Naveed AkramAamir Naveed Akram Dec 2, 2026 869 views

Question details

Count records whose times fall within a range that crosses midnight.

Count Excel Times Across Midnight with COUNTIFS
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.
Before you start

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.

Solution 1Recommended

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.

1
Select a result cell

Click an empty cell where you want to display the count.

2
Enter the formula

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.

3
Check the boundaries

Compare the result with your source cells: 10:00 PM is included, while 4:00 AM is excluded.

Add two COUNTIFS results for time-only values
Date-time values need different boundaries: If the cells include dates, use the date-time solution instead; their underlying values are not time-only values.
Count overnight times in WPS

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. 1. Open your spreadsheet: Open WPS Spreadsheets and choose File > Open to select your workbook.
  2. 2. Check the source values: Select the time column and check whether its cells contain time-only values or full dates and times.
  3. 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. 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.
Count time ranges that cross midnight with COUNTIFSOpen and edit Microsoft Excel XLSX filesUse familiar spreadsheet formulas and cell references
microsoft office alternative - wps office

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.