I have a PHP and MySQL code that should calculate the hours minutes and days of difference between two date and hours. It works well, just adding 20 hours and 20 minutes more than normal. And I remove the DATE part and put the date and time manually, it works fine.
I don't understand what happens.
$fecha = $row["fecha"];
$data= $row["hora"];
$start = strtotime("$fecha $hora");
$currentDate = date("Y-m-d");
$currentTime = date("H:i:s");
$currentDate = date("Y-m-d H:i:s", strtotime($currentDate .$currentTime));
$end = strtotime("$currentDate");
$totaltime = ($end - $start) ;
$hours = intval($totaltime / 3600);
$seconds_remain = ($totaltime - ($hours * 3600));
$minutes = intval($seconds_remain / 60);
$seconds = ($seconds_remain - ($minutes * 60));
$statusfichaje= $row["status"];
if ($statusfichaje == Start){echo '<td>Trabajando'.$hours.':'.$minutes.':'.$seconds.' </td>';}else{echo '<td>'. $row["status"] .'</td>';}
Edit
start 2019-12-29 21:27:50 . end 2019-12-31 0:51:50 = 47:51:16
As you can see it calculates badly.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…