Calculate Conditional Elapsed Hours Between Date-Time Cells in Excel
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.

- 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.
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.
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.
Click the cell where you want to display the elapsed hours.
Type =IF(X95="Yes",0,IF(AND(K95="Yes",X95="No"),(Q110-AP104)*24,"")) and press Enter.
On the Home tab, use the Number Format menu to select Number and adjust the decimal places if needed.

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. Open the workbook: Open WPS Spreadsheets and use Open to select your workbook.
- 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. 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. Display decimal hours: Select the result cell and choose Number from the Home tab's number format controls.

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.




