Calculate day and night hours from a shift based on criteria

VladiArsenal

New Member
Joined
Nov 19, 2020
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hi,

I need a formula to calculate how many hours are night hours if the criteria is that Night hours are after 22:00 and before 06:00. Here is a sample shift that I have:

Start Time: 01-09-2020 05:00:00 PM
End Time: 02-09-2020 01:30:00 AM
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
1605821374420.png



This is what the table looks like, I need the formula for column D
 

Attachments

  • 1605821338707.png
    1605821338707.png
    7.4 KB · Views: 42
Upvote 0
If your End Time is always within 24 hours of the Start Time, try the following formula:
Excel Formula:
=MOD(B2-A2,1)*24-(INT(B2)-INT(A2))*(22-6)-MEDIAN(MOD(B2,1)*24,22,6)+MEDIAN(MOD(A2,1)*24,22,6)
Otherwise, you need a more complex formula.
 
Upvote 0
Yes they are always within 24 hours, the formula works perfectly, thank you very much!
 
Upvote 0

Forum statistics

Threads
1,214,627
Messages
6,120,610
Members
448,973
Latest member
ChristineC

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