Time band hour count

Peter1973

Well-known Member
Joined
May 13, 2006
Messages
963
Office Version
  1. 365
I am looking for a formula to look in times in A1 and A2 (A1 has start time and A2 has finish time and tell me how much of that time crosses over the hours between 1800 and 0600
Example
A1 = 2200 A2= 0800 answer would be 8 hours

Any help appreciated
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
If you have time values in cells A1 and A2 (22:00 and 08:00), try

=(1-MAX(A1,18/24)+MIN(A2,6/24))*24

If you have four-digit numbers (or text strings) in cells A1 and A2, try

=(1-MAX(TEXT(A1,"00\:00"),18/24)+MIN(TEXT(A2,"00\:00"),6/24))*24
 
Upvote 0
Hi, I think below should work:

Code:
=IF(A2>=A1,A2-A1,A2+1-A1)

Given values are in excel time format.
 
Last edited:
Upvote 0
Seems to be working for me:


Book1
ABC
118:00:0012:00
26:00
Sheet5
Cell Formulas
RangeFormula
C1=IF(A2>=A1,A2-A1,A2+1-A1)


is your data in excel date-time format or stored as text ? can you check by using ISNUMBER on time field and see if it gets FALSE.
 
Last edited:
Upvote 0
This counts the total hours whereas i only want to count hours that are between 1800 and 0600 ie if A1 was 2100 and A2 0900 the answer would be 09:00 and the hours from 0600 to 0900 would not be counted.

Thanks
 
Upvote 0
Below should work, in this case if A1 is 05:00:00 and A2 is 06:00:00 then the result will be 01:00:00 but if A1 is Greater than A2 then you will get your desired result. Assumption here is that in cell A1 & A2 you have only time values (with general number format these should be less than 1).


Book1
ABC
118:00:006:00:00
26:00:00
Sheet1
Cell Formulas
RangeFormula
C1=IF(A2-A1<0,A2,A2-A1)
 
Upvote 0
This counts the total hours whereas i only want to count hours that are between 1800 and 0600 ie if A1 was 2100 and A2 0900 the answer would be 09:00 and the hours from 0600 to 0900 would not be counted...
Have you tried formulas offered in Post # 2?
 
Upvote 0

Forum statistics

Threads
1,224,817
Messages
6,181,149
Members
453,021
Latest member
Justyna P

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