我需要计算两个日期之间工作小时数的差异
例如:
$dateStart = '201705151330';
$dataEnd = '201705161230';
$lunchStart = '12:00';
$lunchEnd = '13:30';
在此之前,我可以使用以下代码解决:
$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;
但我需要考虑到从 07:30 到 12:00 以及从 13:30 转移到 17:48 ,所以我需要扣除午餐时间和工作时间。