Highlight Excel Date-Time Cells When the Elapsed Time Is Outside a Range
Question details
Highlight two date-time cells when the elapsed time between them is less than 16 hours or greater than 18 hours.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- A start date and time are in C2, and an end date and time are in C3. Both cells should be highlighted when their difference is outside the specified range.
- Observed behavior
- The desired result is for both cells to be highlighted when the elapsed time is outside the 16-to-18-hour range.
Enter valid Excel date-time values in C2 and C3, with the start in C2 and the end in C3. Include the date as well as the time, especially if the interval crosses midnight.
Apply an Excel conditional formatting formula to both cells
Use one formula-based rule to highlight C2 and C3 whenever the elapsed time is outside the allowed range.
In the worksheet, select the range C2:C3.
Go to Home > Conditional Formatting > New Rule, then choose Use a formula to determine which cells to format.
In the formula box, enter =OR($C$3-$C$2<TIMEVALUE("16:00:00"),$C$3-$C$2>TIMEVALUE("18:00:00")).
Click Format, choose a fill color, and click OK. Click OK again to save the rule.

Highlight out-of-range date-time intervals in WPS Spreadsheet
Use a formula-based conditional formatting rule in WPS Spreadsheet to highlight both date-time cells when their elapsed time is outside the 16-to-18-hour range.
- 1. Open the workbook: Open WPS Spreadsheet and use Open to select your Excel workbook.
- 2. Select the cells: Enter the start date and time in C2 and the end date and time in C3, then select C2:C3.
- 3. Create the rule: Go to Home > Conditional Formatting > New Rule and choose the option to use a formula. Enter =OR($C$3-$C$2<TIMEVALUE("16:00:00"),$C$3-$C$2>TIMEVALUE("18:00:00")).
- 4. Set the format and save: Choose a fill color, confirm the rule, and use File > Save to save the workbook.

Frequently Asked Questions
Are intervals of exactly 16 or 18 hours highlighted?
No. The formula uses less than 16 hours and greater than 18 hours, so both boundary values remain unhighlighted.
Will the formula work across midnight?
Yes, if both C2 and C3 contain complete, valid date-time values. Include the correct date in each cell so the subtraction accounts for the change of day.
Why are both cells highlighted by the same rule?
The rule applies to C2:C3, and the absolute references $C$2 and $C$3 make both cells evaluate the same elapsed-time calculation.
How can I change the allowed time range?
Go to Home > Conditional Formatting > Manage Rules, edit the rule, and replace the times in TIMEVALUE("16:00:00") and TIMEVALUE("18:00:00") with your desired limits.




