I have the following problem with a function that I use to add two hours, one of the hours comes from a query, which is a TIME type field and the other hour is the one I send for a POST. What I want is to add to the time that the query brought me the hours that arrive by POST, to keep the amount of hours worked in the week:
Ex:
Hours printed in the query 16:00:00
Hours that arrive by POST to add them to the table field: 07:59:00
Result: 23:59:00
Now the problem is when the result goes to 24:00:00, example:
Hour 1: 16:00:00
Hour 2: 08:00:00
The result should be 24:00:00
but what it shows is 00:00:00
The function is as follows:
function SumaHoras($hora1,$hora2){
$a = new DateTime($hora1);
$b = new DateInterval((new DateTime($hora2))->format('\P\TH\Hi\Ms\S'));
$a->add($b); //Sumo las horas
return $a->format('H:i:s'); //Imprimo las horas
}
I notice that the problem is when the time passes from 23:59:59 which is when it reaches 24.
What I can think of is that it takes a maximum of 24 hours, I think because of the format I give it in the return.
But I can not find a way to solve it, I would appreciate a help.