1
Good morning, I would like to know that someone can help me create an interface in conjunction with the calculation, in PHP, between hours of work with minutes of pause. That is, we would have an input time entered by the user and an output time. In a separate input a pause hours/minutes input.
I have seriously tried to make the necessary calculations to give correctly, but the hours and minutes minus the break, have gone wrong.
I leave here a little of the code I have made.
<input type="text" name="horai" id="horai" style="border: 1px solid #ccc; border-radius: 4px; padding: 6px;" required/>
<input type="text" name="horaf" id="horaf" style="border: 1px solid #ccc; border-radius: 4px; padding: 6px;" required/>
<?php
if($_POST['horai'] > $_POST['horaf']){
$total = (24 - $_POST['horai'] + $_POST['horaf']);
}else{
$total = $_POST['horaf'] - $_POST['horai'];
}
$iTime= strtotime($_POST['horai']);
$fTime= strtotime($_POST['horaf']);
if($fTime> $iTime){
$diferenca = $fTime- $iTime;
$semintervalo = date('H:i', $diferenca);
} else {
$diferenca = (24 - $iTime) + $fTime;
$semintervalo = date('H:i', $diferenca);
}
$tempodepausa= strtotime($_POST['pausa']);
$tempodepausaaux= $diferenca- $semintervalo;
$comintervalo = date('H:i', $tempodepausaaux);
echo 'Diferença entre Horas (s): '.$diferenca.'<br/>';
echo 'Diferença entre Horas (H:m): '.$semintervalo.'<br/>';
echo 'Tempo útil (H:m): '.$comintervalo.'<br/>';
echo 'Tempo útil (s): '.$tempodepausaaux;
?>
And how should these inputs be entered? Can I type 08:00 for initial and 15:00 for final? or 16 April 23:00 and 17 April 2:00 that the code will work properly?
– user60252
10:00 - 15:00 of the same day works. For different days I have not tested why I separated the code.
– White
My PC code works perfectly. I don’t understand how it gives you those values. See if type="date" or "datetime"
– White
Yes, you have to type correctly in the format
ano-mes-dia hh:mm:ss
to work properly. Hassle when typing!!!– user60252
On your pc to start
2018-04-16 8:00:00
to the end2018-04-17 8:00:00
(24 hours) and 1 hour interval when returns?– user60252
@Leocaracciolo the problem is not in the code itself. The problem is in the time_zone. I will edit the answer.
– Andrei Coelho
@Andreicoelho, I’m not asking about the code, I’m asking about the input of data into the inputs that are text type. This way the user will have to be soothsayer or keep trying, trying ....
– user60252
@Leocaracciolo yes.. I understood. But take the test now. It won’t change the value. The problem was just that. Anyway, thank you. As I had not tested on another server, this would bring problems.
– Andrei Coelho
@Andreicoelho, blz, my purpose was to help AP validate the inputs with the inputs correctly so that the code works. Note that any type of entry is accepted. But anyway .... never mind .... lacked interest on his part
– user60252
@Leocaracciolo yes! That’s right! It’s important that he validates BEFORE starting this process.
– Andrei Coelho
I use a Picker data in the middle and validates me automatically. This was all just to get to know which calculations were wrong. Andrei helped a lot.
– White
@White quiet friend!
– Andrei Coelho