I am trying to make a spreadsheet that calculates how long I've worked. The problem is, I work nights sometimes and need a calculator that will calculate start times from PM to AM. What I have now calculates it wrong. I took the formulas from another spreadsheet.

Here is what I have so far (only A4 and B4 calculate at the moment). It is a OpenOffice spreadsheet.

Does anyone know how to do this? Thanks!