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
 

Some videos you may like

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.

VladiArsenal

New Member
Joined
Nov 19, 2020
Messages
3
Office Version
  1. 365
Platform
  1. Windows
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: 10

Tetra201

MrExcel MVP
Joined
Oct 14, 2016
Messages
3,631
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.
 

VladiArsenal

New Member
Joined
Nov 19, 2020
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Yes they are always within 24 hours, the formula works perfectly, thank you very much!
 

Watch MrExcel Video

Forum statistics

Threads
1,122,455
Messages
5,596,231
Members
414,047
Latest member
debbos

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
Top