Add Total Hours Overdue [duplicate]

1

I am in doubt as to how I could perform the sum (time format) of the records that were returned in the query.

I'm picking up the office start time considering that above 08:01 it is delayed through there calculating how many minutes in arrears the employee is ...

if ($GetEntrada >= '08:01:00') {
  $horaEntrada = '08:01:30';
  $entrada = $tMC['Hora_Entrada'];
  $total = (strtotime($entrada) - strtotime($horaEntrada));
  $hora = floor($total / 60 / 60);
  $minutos = round(($total - ($hora * 60 * 60)) / 60);
  $hora = str_pad($hora, 2, "0", STR_PAD_LEFT);
  $minutos = str_pad($minutos, 2, "0", STR_PAD_LEFT);
  $atraso = $hora.':'.$minutos;
} else {
  $atraso = "00:00";
}

echo "
  <tr>
    <td>$DataN[2]/$DataN[1]/$DataN[0]</td>
    <td>$atraso</td>
    <td>{$tMC['Hora_Entrada']}</td>
    <td>{$tMC['Hora_InicioIntervalo']}</td>
    <td>{$tMC['Hora_FimIntervalo']}</td>
    <td>{$tMC['Hora_Saida']}</td>
  </tr>
";

I would like to compute all values of "<td>$atraso</td>" as shown in the attachment below and display in time format.

    
asked by anonymous 23.04.2018 / 20:41

1 answer

2

You can do this easily with the native class DateTime :

$d1 = new DateTime('2018-04-23 11:20:33');
$d2 = new DateTime('2018-04-23 08:01:00');

$atraso = $d1->diff($d2);

echo $atraso->format('%H:%i:%s'), PHP_EOL;  // 03:19:33

See working at Repl.it | Ideone | GitHub GIST

Where $d1 would be the employee's time of entry and $d2 the start time of the file.

    
23.04.2018 / 21:48