Formatting Issues

Highlight Excel Date-Time Cells When the Elapsed Time Is Outside a Range

Nimra MalikNimra Malik Nov 22, 2026 868 views

Question details

Highlight two date-time cells when the elapsed time between them is less than 16 hours or greater than 18 hours.

Highlight Excel Date-Time Cells When the Elapsed Time Is Outside a Range
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.
Before you start

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.

Solution 1Recommended

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.

1
Select both date-time cells

In the worksheet, select the range C2:C3.

2
Create a formula rule

Go to Home > Conditional Formatting > New Rule, then choose Use a formula to determine which cells to format.

3
Enter the formula

In the formula box, enter =OR($C$3-$C$2<TIMEVALUE("16:00:00"),$C$3-$C$2>TIMEVALUE("18:00:00")).

4
Choose the highlight

Click Format, choose a fill color, and click OK. Click OK again to save the rule.

Apply an Excel conditional formatting formula to both cells
Range boundaries: Exactly 16 hours and exactly 18 hours are not highlighted. The dollar signs keep both cells referring to the same start and end values.
WPS Spreadsheet

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. 1. Open the workbook: Open WPS Spreadsheet and use Open to select your Excel workbook.
  2. 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. 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. 4. Set the format and save: Choose a fill color, confirm the rule, and use File > Save to save the workbook.
Highlight both date-time cells with one formula-based rule.Open and save Microsoft Excel XLSX files.Use familiar spreadsheet formatting tools in a free Office suite.
microsoft office alternative - wps office

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.