Dear Excelers,

How to count working hours between two different periods?

For example:

I am working in overtime claim form; where I have two different periods, for the reason that every period has a different rate:
1) Period (1) 4:00-21:00, at the rate of 125%.
2) Period (2) 21:00-4:00, at the rate of 150%.


Problem:

Where A2 (On Overtime), and B2 (Off Overtime): A2=20:00, & B2=5:00.

An employee claim over time from: 20:00-5:00, that falls into two periods:
1) From 20:00-21:00, Period (2).
2) From 21:00-4:00, Period (1).
3) From 4:00-5:00, Period (2).

C is Period (1) and D is Period (2).

I want to be: C=7, and D=2.

Is it possible in Excel?!