How to calculate times between a range with two conditions

amusaber

New Member
Joined
Oct 22, 2023
Messages
2
Office Version
  1. 2021
  2. 2019
Platform
  1. Windows
How to calculate times between a range with two conditions?
times 01.JPG






times 01.xlsx
ABCDE
1start timeend timehow much times in range (00:00 - 07:00)how much times in range (20:00 - 23:59)how much times not in these two ranges
23:0021:004:001:0013:00
3*formula1*formula2*formula3
4
5*I need formulas for yellow parts
Sheet1
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Try this

Book1
ABCDE
1start timeend timehow much times in range (00:00 - 07:00)how much times in range (20:00 - 23:59)how much times not in these two ranges
203:0021:0004:0001:0013:00
3*formula1*formula2*formula3
Sheet1
Cell Formulas
RangeFormula
C2C2=(SUMPRODUCT(--(ROW(INDIRECT(1&":"&7))>=A2*24)*(ROW(INDIRECT(1&":"&7))<7)))/24
D2D2=SUMPRODUCT(--(ROW(INDIRECT(B2*24&":"&24))>=A2*24)*(ROW(INDIRECT(B2*24&":"&24))<=B2*24))/24
E2E2=(SUMPRODUCT(--(ROW(INDIRECT(1&":"&24))>=A2*24)*(ROW(INDIRECT(1&":"&24))<=B2*24))-(C2*24)-(D2*24)-1)/24


Last part was confusing so i just tried a fluke
 
Upvote 0
Try this

Book1
ABCDE
1start timeend timehow much times in range (00:00 - 07:00)how much times in range (20:00 - 23:59)how much times not in these two ranges
203:0021:0004:0001:0013:00
3*formula1*formula2*formula3
Sheet1
Cell Formulas
RangeFormula
C2C2=(SUMPRODUCT(--(ROW(INDIRECT(1&":"&7))>=A2*24)*(ROW(INDIRECT(1&":"&7))<7)))/24
D2D2=SUMPRODUCT(--(ROW(INDIRECT(B2*24&":"&24))>=A2*24)*(ROW(INDIRECT(B2*24&":"&24))<=B2*24))/24
E2E2=(SUMPRODUCT(--(ROW(INDIRECT(1&":"&24))>=A2*24)*(ROW(INDIRECT(1&":"&24))<=B2*24))-(C2*24)-(D2*24)-1)/24


Last part was confusing so i just tried a fluke
thank you alot, but its too confusing for me to understand 😵
 
Upvote 0
Time 2023.xlsm
ABCDE
1start timeend timehow much times in range (00:00 - 07:00)how much times in range (20:00 - 23:59)how much times not in these two ranges
23:0021:004:001:0013:00
2cc
Cell Formulas
RangeFormula
C2C2=MIN(7/24,B2)-A2
D2D2=MIN(0.99999,B2)-MAX(A2,20/24)
E2E2=B2-A2-C2-D2
 
Upvote 0
Time 2023.xlsm
ABFG
1start timeend timeTotalRegular
23:0021:0018:0013:00
2cc
Cell Formulas
RangeFormula
F2F2=B2-A2
G2G2=MIN(20/24,B2)-MAX(7/24,A3)
 
Upvote 0
In C2

=MEDIAN(0,TIMEVALUE("7:00:00"),$B2)-MEDIAN(0,TIMEVALUE("7:00:00"),$A2)

In D2

=MEDIAN(TIMEVALUE("20:00:00"),1,$B2)-MEDIAN(TIMEVALUE("20:00:00"),1,$A2)

In E2

=$B2-$A2-$C2-$D2
 
Upvote 0

Forum statistics

Threads
1,215,161
Messages
6,123,378
Members
449,097
Latest member
Jabe

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top