Sorry, saw the bit about 24 not 12/12 and thought that was your problem.
You can, and should, use the mysql date and time functions to do this for you. Guessing at your table layout, and assuming that you are using TIME or DATETIME columns to store the times
$sql = "SELECT id, TIMEDIFF(start, end) as t FROM table";
This will work with both time and datetime column types. It will return hrs:mins:secs and you can either enclose it in the sql EXTRACT function to extract just the part you need, or do it in php, up to you.
PS both columns MUST be the same data type, and it is only from mysql ver 4.1.1 up, sorry.