Sum Total Hours Overdue

Asked

Viewed 401 times

1

I’m wondering how I could accomplish the sum (time format) of the records that were returned in the query.

I’m picking up the office hours considering that above 08:01 it’s delayed through there calculating how many minutes late 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 calculate all the values of "<td>$atraso</td>" as shown in the attachment below and display in time format.

inserir a descrição da imagem aqui

  • Which php version is using?

  • I am using Version 5.6, if necessary I can update quickly...

  • If necessary

  • Hello Friend Anderson, This you quoted explains about the difference between two dates, my question is a little different, As I would do to sum up all the delays to be able to define the total of Hours late (Whole month) of the values contained in the "<td>$delay</td>"

  • I got the solution for what I needed in this topic pt.stackoverflow.com/questions/215123/... , I apologize if I ended up expressing myself badly or unable to explain well, thank you very much

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 on Repl.it | Ideone | Github GIST

Where $d1 would be the employee’s entry time and $d2 opening hours of business.

  • Perfect, this I would use to see how long the employee delayed on 23/04/2018, but how I would do to sum up all the delays to be able to set the total of Hours in arrears (Whole month)?

  • @Benhurdasilveirakulzer in this case you will have to make one explode value and sum hours and minutes separately

  • but if the sum of the minutes passes 60, as I would add 1 hour and resume the sum?

  • @Benhurdasilveirakulzer entire division and division rest

  • Thanks guys, I will try to apply this solution and anything I warn here again!

  • I got the solution for what I needed in this topic https://answall.com/questions/215123/como-somar-valores-de-uma-coluna-na-table, I apologize if I ended up expressing myself badly or not being able to explain well, thank you guys

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.