$start_total = 60*$row[2] + $row[3]; $end_total = 60*$row[4] + $row[5]; $total_time = $end_total - $start_total; # in minutes