title: Difference of hours worked between two dates excluding lunch break
body: <p>I need to calculate the difference of hours worked between two dates</p>
  
  <p>ex:</p>
  
  <pre><code>$dateStart = '201705151330';
  $dataEnd = '201705161230';  
  $lunchStart = '12:00';  
  $lunchEnd = '13:30'; 
  </code></pre>
  
  <p>Until then I can solve with the following code:</p>
  
  <pre><code>$dateStart = '201705151330';
  $dataEnd = '201705161230';  
  $lunchStart = '12:00';  
  $lunchEnd = '13:30'; 
  
  $datatime1 = new DateTime($dateStart);
  $datatime2 = new DateTime($dataEnd);
  
  
  $data1  = $datatime1-&gt;format('Y-m-d H:i:s');
  $data2  = $datatime2-&gt;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;
  </code></pre>
  
  <p>But I need to take into account that the shift is from <strong>07:30</strong> to <strong>12:00</strong> and from <strong>13:30</strong> to <strong>17:48</strong>, so I need to deduct lunchtime and hours not worked.</p>