Calculation Issues

Calculate Conditional Elapsed Hours Between Date-Time Cells in Excel

Huma Ashraf ChHuma Ashraf Ch Nov 18, 2026 869 views

Question details

Calculate elapsed hours between two date-time cells only when K95 is Yes and X95 is No, and return zero when X95 is Yes.

Calculate Conditional Elapsed Hours Between Date-Time Cells in Excel
Product
Microsoft Excel
Device & OS
not provided
Scenario
A worksheet uses AP104 as the start date and time, Q110 as the end date and time, and K95 and X95 as conditions.
Observed behavior
The desired result is elapsed hours when both conditions are met, zero when X95 is Yes, and a blank otherwise.
Before you start

Check that AP104 and Q110 contain valid Excel date-time values, with AP104 as the start and Q110 as the end. Confirm that K95 and X95 contain the intended Yes or No values.

Solution 1Recommended

Use an IF formula to calculate conditional elapsed hours

Use this formula to return decimal hours, zero, or a blank according to the values in K95 and X95.

Excel stores dates and times as day values, so subtracting the start from the end and multiplying by 24 returns elapsed hours, including periods longer than one day.

1
Select the result cell

Click the cell where you want to display the elapsed hours.

2
Enter the formula

Type =IF(X95="Yes",0,IF(AND(K95="Yes",X95="No"),(Q110-AP104)*24,"")) and press Enter.

3
Format the result

On the Home tab, use the Number Format menu to select Number and adjust the decimal places if needed.

Use an IF formula to calculate conditional elapsed hours
Negative durations and multi-day periods: If negative results should be prevented, replace (Q110-AP104)*24 with MAX(0,(Q110-AP104)*24). Avoid HOUR() for elapsed time because it returns an hour component rather than total hours across multiple days.
Calculate elapsed time in WPS Spreadsheets

Calculate conditional elapsed hours in WPS Spreadsheets

Use the same IF and AND formula in WPS Spreadsheets to calculate decimal hours between two date-time cells based on your worksheet conditions.

  1. 1. Open the workbook: Open WPS Spreadsheets and use Open to select your workbook.
  2. 2. Check the source cells: Select AP104 and Q110 to confirm they contain the start and end date-times, and check K95 and X95 for the condition values.
  3. 3. Enter the formula: Select an empty result cell, enter =IF(X95="Yes",0,IF(AND(K95="Yes",X95="No"),(Q110-AP104)*24,"")), and press Enter.
  4. 4. Display decimal hours: Select the result cell and choose Number from the Home tab's number format controls.
Calculate elapsed hours across multiple daysApply Yes and No conditions with IF and ANDOpen and edit Microsoft Excel XLSX filesUse familiar spreadsheet formatting controls
microsoft office alternative - wps office

Frequently Asked Questions

Why does the formula multiply the date-time difference by 24?

Excel and WPS Spreadsheets store date-time differences in days. Multiplying Q110-AP104 by 24 converts that difference to hours.

What happens if X95 is Yes?

The formula returns zero when X95 is Yes, regardless of the value in K95.

Why is the result blank when X95 is No?

When X95 is No, the formula calculates hours only if K95 is also Yes. Check both cells for the intended values.

Can the formula calculate more than 24 hours?

Yes. Direct date-time subtraction includes the date as well as the time, so (Q110-AP104)*24 returns total elapsed hours across multiple days.

How do I reference date-time cells on another sheet?

Add the sheet name before each reference, such as 'Sheet 2'!Q110 and 'Sheet 2'!AP104, in the formula bar.