Hello 🙂
I have a script where the purpose is to subtract my hours at work from one another, to find out how many hours i actually worked that day.
Here's my script:
function sub_time($time1, $time2, $month, $day, $year) {
//first get the minutes and hours of time 1 and 2
$time_start = explode(":", $time2);
$time_stop = explode(":", $time1);
//now convert the time...
$start1 = mktime($time_start[0], $time_start[1], 0, $month, $day, $year);
$stop1 = mktime($time_stop[0], $time_stop[1], 0, $month, $day, $year);
$newtime = ($stop1 - $start1);
return date('h:i', $newtime);
}
Now for use we could say:
$getTimer[$i] = sub_time("20:15", "9:30","10","5","1999");
this returns: 11:45 - which is incorrect.. it actually should be 10:45. Now i have searched and searched the net and here for an answer without luck 🙂, I even played with it myself and put in somecode that checks if the minutes are set and if they are to subtract an hour from the hours, before displaying it.
However, it is only in some cases that it actually is missing an hour - not all. For exampled:
$getTimer[$i] = sub_time("20:00", "10:00","10","5","1999");
this does correctly return 10.
$getTimer[$i] = sub_time("20:15", "10:00","10","5","1999");
this also correctly returns 10:15 - now I'm a bit confused... Anyone that can see a problem with my code 🙂?
i realize month by the way that month, day and year is a bit over the edge here, but is used in a different part of the script. 🙂
Thanks in advance 🙂