=IF(AND(A2>=TIME(18,0,0),B2<TIME(6,0,0)),B2-A2,IF(OR(A2>=TIME(18,0,0),A2<TIME(6,0,0)),TIME(6,0,0)-A2,0))
Assuming your start time is in cell A2 and end time is in cell B2, you would place this formula in the cell where you want the result to appear. Adjust the cell references as needed for...