Good morning, I'd like to know that someone can help me create an interface in conjunction with the calculation in PHP between working hours and minutes of pause. That is, we would have an input time entered by the user and an exit time. In a separate input an hour / minute pause input.
I have tried seriously to make the necessary calculations to give correctly, but the hours and minutes minus the range, have given wrong.
I leave here some of the code I have done.
<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;
?>