I want to get the Time in and Time out then get the rendered hours, minutes and seconds but im having a problem on subtracting time here is a sample result
Time in: 10:00:33 Time out: 10:01:30
Total Hours rendered: 0 Total Minutes rendered: 1 Total Seconds rendered: -3
in the sample above it returns 1 minute already even though its not 1 minute yet and in the seconds it returns a negative value
here is my code
$time_out = date("H:i:s");
$nerd->time_out = $time_out;
$time_o = explode(":", $time_out);
$time = explode(":", $nerd->time_in);
$hours = $time_o[0] - $time[0];
$minutes = $time_o[1] - $time[1];
$seconds = $time_o[2] - $time[2];
if($minutes < 2){
$minutes_r = 0;
}else if($minutes <= 15){
$minutes_r = 15;
}else if($minutes <= 30){
$minutes_r = 30;
}else if($minutes <= 45){
$minutes_r = 45;
}else{
$minutes_r = 0;
}
in my code I explode the time to get values in hours, minutes and seconds.
Can anyone suggest a better way of doing this so there will be no negative results?