I need to calculate the difference of hours worked between two dates
ex:
$dateStart = '201705151330';
$dataEnd = '201705161230';
$lunchStart = '12:00';
$lunchEnd = '13:30';
Until then I can solve with the following code:
$dateStart = '201705151330';
$dataEnd = '201705161230';
$lunchStart = '12:00';
$lunchEnd = '13:30';
$datatime1 = new DateTime($dateStart);
$datatime2 = new DateTime($dataEnd);
$data1 = $datatime1->format('Y-m-d H:i:s');
$data2 = $datatime2->format('Y-m-d H:i:s');
$data1 = strtotime($data1);
$data2 = strtotime($data2);
$nHours = ($data2 - $data1) / 3600;
$nMinutes = (($data2 - $data1) % 3600) / 60;
$total = sprintf('%02d:%02d', $nHours , $nMinutes);
echo $total;
But I need to take into account that the shift is from 07:30 to 12:00 and from 13:30 to 17:48, so I need to deduct lunchtime and hours not worked.