I need to calculate the difference in working hours between two dates
ex:
$dataIni = '201705151330';
$dataFim = '201705161230';
Until then I can solve it with the following code:
$dataIni = '201705151330';
$dataFim = '201705161230';
$datatime1 = new DateTime($dataIni);
$datatime2 = new DateTime($dataFim);
$data1 = $datatime1->format('Y-m-d H:i:s');
$data2 = $datatime2->format('Y-m-d H:i:s');
$data1 = strtotime($data1);
$data2 = strtotime($data2);
$nHoras = ($data2 - $data1) / 3600;
$nMinutos = (($data2 - $data1) % 3600) / 60;
$total = sprintf('%02d:%02d', $nHoras , $nMinutos);
echo $total;
But I need to take into account the shift from 07:30 to 12:00 and from 13:30 until 17:48 , ie you need to discount lunch and unpaid hours. How can I solve this in PHP?