Meera Meera - 1 month ago 10
PHP Question

finding out difference between two times

I wrote the following code to determine the amount of time that employees spend on a task:

$time1 = $row_TicketRS['OpenTime'];
$time2= $row_TicketRS['CloseTime'];

$t1=strtotime($time1);
$t2=strtotime($time2);


$end=strtotime(143000); //143000 is reference to 14:30


//$Hours =floor((($t2 - $t1)/60)/60);

$Hours = floor((($end- $t1)/60)/60);


echo $Hours.' Hours ';


The above code is not giving me the correct time.

For example, with a start time of 09:19:00 and end time of 11:01:00 it give me duration time of only 1 hour which is wrong. What is the correct way?

Answer

after changing strtotime('14:30:00') everything working fine.. see below

$time1 = '09:19:00';
$time2= '11:01:00';

echo "t1".$t1=strtotime($time1); 
echo "<br/>t2:".$t2=strtotime($time2);    

echo "<br/>end:".$end=strtotime('14:30:00'); 
echo  "<br/>floor value:";  
var_dump(floor((($end- $t1)/60)/60));     

//$Hours =floor((($t2 - $t1)/60)/60); 

$Hours = floor((($end- $t1)/60)/60);    

echo   $Hours.' Hours '