Calculation of time arrays by $_POST in PHP

Asked

Viewed 31 times

1

I have a dynamic form from which comes the name of the interruption, start time and end time. It must return the interruptions and times added, but in the total field of lost hours it has to subtract the ending by the beginning and add another interruption if it has. Example below:

Exemplo

The problem is that it’s showing in total, the first calculation, and the sum. Code below:

  $mostrar = 0;
  $somah = 0;
  $somam = 0;
  for ($i=0; $i < count($_POST['interrupcao']); $i++) {

   $total = strtotime($_POST['terminoint'][$i]) - strtotime($_POST['inicioint'][$i]);
   $horas      = floor($total / 60 / 60);
   $minutos    = round(($total - ($horas * 60 * 60)) / 60);

   $somah += $horas;
   $somam += $minutos;

   $mostrar .= $somah.":".$somam;

   $html .="<tr>";
   $html .="<td>{$_POST['interrupcao'][$i]}</td>";
   $html .="<td>{$_POST['inicioint'][$i]}</td>";
   $html .="<td>{$_POST['terminoint'][$i]}</td>";
   $html .= "</tr>";
  }
  • I think this might help you a little bit: https://answall.com/questions/51821/howto get o-formato-formato-horas-quando-esta-supera-24/51826#51826

  • 1

    I also created a library that helps me when I need to calculate these things :p

  • Thank you, I’ll check this library =)

  • I still can’t fix it =/

No answers

Browser other questions tagged

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