Calculate time spent in hourly interval

phiero21

Board Regular
Joined
Sep 20, 2007
Messages
136
Hi, I have Start time and End Time in excel (sometimes they can spread over days) and want to know the time spend in each hourly interval from 0 to 24.
So I want Col E to Col AB populated via a formulae and I have also entered the expected value for each cell there.
Please if anyone can help.

Also, if anyone can please explain why I have to round the log sec column. I tried (B2-A2)*24*2600 and formatted to numbers but it was giving values in decimal. Shouldn't it automatically give the right number of seconds without rounding off.


Book1
ABCDEFGHIJKLMNOPQRSTUVWXYZAAAB
1Hourly Interval
2Start TimeEnd TimeLog Sec01234567891011121314151617181920212223
34/22/2024 5:05:304/22/2024 5:05:40100000010000000000000000000
44/22/2024 5:05:304/22/2024 6:05:40361000000327034000000000000000000
54/22/2024 5:05:304/22/2024 17:10:054347500000327036003600360036003600360036003600360036003600605000000
64/22/2024 22:20:304/23/2024 2:10:101378036003600610000000000000000000023703600
74/22/2024 5:05:304/23/2024 22:05:30147600360036003600360036006870720072007200720072007200720072007200720072007200720072007200720039303600
Sheet1
Cell Formulas
RangeFormula
G2:AB2G2=F2+1
C3:C7C3=ROUND((B3-A3)*24*3600,0)
Cells with Conditional Formatting
CellConditionCell FormatStop If True
E3:AB7Cell Value=0textNO
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
You don't say what version of excel you are running - so I did it where I could think of a way - in 365. I can't think of a good way to do it in older versions - I'd like to see it.

MrExcelPlayground22.xlsx
ABCDEFGHIJKLMNOPQRSTUVWXYZAAAB
1Hourly Interval
2Start TimeEnd TimeLog Sec01234567891011121314151617181920212223
34/22/2024 5:05:304/22/2024 5:05:40100000010000000000000000000
44/22/2024 5:05:304/22/2024 6:05:40361000000327034000000000000000000
54/22/2024 5:05:304/22/2024 17:10:054347500000327036003600360036003600360036003600360036003600606000000
64/22/2024 22:20:304/23/2024 2:10:101378036003600610000000000000000000023703600
74/22/2024 5:05:304/23/2024 22:05:30147600360036003600360036006870720072007200720072007200720072007200720072007200720072007200720039303600
Sheet7
Cell Formulas
RangeFormula
G2:AB2G2=F2+1
E3:AB7E3=LET(a,$A3,b,$B3,c,(b-a)*24*60*60+1,d,SEQUENCE(c,1,a,1/24/60/60),e,HOUR(d),f,ROWS(FILTER(e,e=E$2)),IFERROR(f,0))
C3:C7C3=ROUND((B3-A3)*24*3600,0)
Cells with Conditional Formatting
CellConditionCell FormatStop If True
E3:AB7Expression=E3=0textNO


As for the need to round? Time is a bit funny in excel and tiny errors pop in. (That's of little help)
 
Upvote 1
Solution
You don't say what version of excel you are running - so I did it where I could think of a way - in 365. I can't think of a good way to do it in older versions - I'd like to see it.

MrExcelPlayground22.xlsx
ABCDEFGHIJKLMNOPQRSTUVWXYZAAAB
1Hourly Interval
2Start TimeEnd TimeLog Sec01234567891011121314151617181920212223
34/22/2024 5:05:304/22/2024 5:05:40100000010000000000000000000
44/22/2024 5:05:304/22/2024 6:05:40361000000327034000000000000000000
54/22/2024 5:05:304/22/2024 17:10:054347500000327036003600360036003600360036003600360036003600606000000
64/22/2024 22:20:304/23/2024 2:10:101378036003600610000000000000000000023703600
74/22/2024 5:05:304/23/2024 22:05:30147600360036003600360036006870720072007200720072007200720072007200720072007200720072007200720039303600
Sheet7
Cell Formulas
RangeFormula
G2:AB2G2=F2+1
E3:AB7E3=LET(a,$A3,b,$B3,c,(b-a)*24*60*60+1,d,SEQUENCE(c,1,a,1/24/60/60),e,HOUR(d),f,ROWS(FILTER(e,e=E$2)),IFERROR(f,0))
C3:C7C3=ROUND((B3-A3)*24*3600,0)
Cells with Conditional Formatting
CellConditionCell FormatStop If True
E3:AB7Expression=E3=0textNO


As for the need to round? Time is a bit funny in excel and tiny errors pop in. (That's of little help)
Thanks, exactly what I needed. Really appreciate your help :)
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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