In F2, use
=IF(AND($D2<=F$1,$E2>=F$1),MIN($C2,$B2-SUM($E2:E2)+$E2),"")
and copy down and across. Note, there is no error checking in this formula, so for instance, if you put 21 hours in B2, as you only have a date span of 2 days, it will only quietly allocate 20 of those 21 hours.