Why not just use a formula?

Assuming weekends get included

=(INT(E2-D2)*("18:00"-"09:00")
+MEDIAN(MOD(E2,1),"18:00","09:00")
-MEDIAN(MOD(D2,1),"18:00","09:00"))*24