I need to subtact time and am getting nowhere fast. The time is passed from a form and in the format $start_hour, $start_minutes, and $start_ampm (where it could be "am" or "pm"). I also have $end_* variables for the end time. If the end time is pm I add 12 hours to it and subtract the start time from the end time.
My problem is the hours almost never come out correctly. Here is some example code that I have been testing with to illustrate the issue.
<?php
echo "Time test<br>\n";
$start_hour="8";
$start_minutes="30";
$end_hour="8";
$end_minutes="35";
$start_ampm="am";
$end_ampm="am";
echo "start: $start_hour:$start_minutes $start_ampm<br>\n";
echo "end: $end_hour:$end_minutes $end_ampm<br>\n";
// addition of 12 left out since I am only testing am stuff at the moment
$begin=gmmktime($start_hour,$start_minutes,"0","1","3","2000");
$end=gmmktime($end_hour,$end_minutes,"0","1","3","2000");
$result=gmdate("g:i",$end-$begin);
echo "Result is $result";
?>
And here is what I get back:
Time test
start: 8:30 am
end: 8:35 am
Result is 12:05
Any ideas?
Brian
PS this is on Linux and running PHP 4.0.1pl2