Datediff subtract time between two times (non working hours)

I am using datediff to work out how many hours and minutes it takes to go from one department (timestamped) to another department (timestamped).

If a department starts the task but doesn’t complete it that working day, but finishes the following day, the data is ‘incorrect’ as it has added non-working hours (overnight) to it.

This is being displayed through the DataTables plugin.

Please, can I get advice on creating a SQL Statement that ignores or subtracts the non-working hours?

Or maybe there is a better way around this?

Current PHP Code:

<table id="example" class="SizeTable" border="1" width="100%">
<thead>
<tr>
<th style="font-size: 1rem">PON</th>
<th style="font-size: 1rem">Total Doors</th> 
<th style="font-size: 1rem">Fold<br>Complete</th> 
<th style="font-size: 1rem">Folding Time<br>H:M</th> 
<th style="font-size: 1rem">Weld<br>Complete</th>
<th style="font-size: 1rem">Welding Time<br>H:M</th> 
<th style="font-size: 1rem">Painted<br>Complete</th>
<th style="font-size: 1rem">Painting Time<br>H:M</th> 
<th style="font-size: 1rem">Assembly<br>Complete</th>  
<th style="font-size: 1rem">Ordered<br>Date</th>
<th style="font-size: 1rem">Lead<br>Time</th>
<th style="font-size: 1rem">Due<br>Date</th> 
</tr>
</thead>
<tbody>
<?php
    include('connection.php');
    $select_query = mysqli_query($connection,"SELECT PON, dateOn, dueDate, foldedStart, weldedStart, paintedStart, assemblyStart, DATEDIFF(dueDate,dateOn) AS days, (
    requiredDoors +
    requiredDoors2 +
    requiredDoors3 +
    requiredDoors4 +
    requiredDoors5 +
    requiredDoors6 +
    requiredDoors7 +
    requiredDoors8 +
    requiredDoors9 +
    requiredDoors10 +
    requiredDoors11 +
    requiredDoors12 +
    requiredDoors13 +
    requiredDoors14 +
    requiredDoors15 +
    requiredDoors16 +
    requiredDoors17 +
    requiredDoors18 +
    requiredDoors19 +
    requiredDoors20 
    ) AS total FROM WIP2 WHERE status = '12'
    OR DATEPART(WEEKDAY,foldedStart) NOT IN (7, 1)
    AND assemblyStart NOT LIKE '%red%' 
    AND assemblyStart NOT LIKE '%InProgress%' 
    AND paintedStart NOT LIKE '%red%' 
    AND paintedStart NOT LIKE '%InProgress%' 
    AND weldedStart NOT LIKE '%red%' 
    AND weldedStart NOT LIKE '%InProgress%' 
    AND foldedStart NOT LIKE '%red%' 
    AND foldedStart NOT LIKE '%InProgress%' 
    ORDER BY dueDate desc");
    while($data = mysqli_fetch_array($select_query)){
?>
<?php
  $fold = date_create($data["foldedStart"]);
  $weld = date_create($data["weldedStart"]);
  $paint = date_create($data["paintedStart"]);
  $assembly = date_create($data["assemblyStart"]);  
  $interval1 = date_diff($fold, $weld);
  $interval2 = date_diff($weld, $paint);
  $interval3 = date_diff($paint, $assembly);
?>
<tr>
<td><?php echo $data['PON']; ?></td>
<td><?php echo $data['total']; ?></td>  
  
<td><?php echo $data['foldedStart']; ?></td>
<td><?php echo $interval1->format('%H:%I'); ?></td>
<td><?php echo $data['weldedStart']; ?></td>
<td><?php echo $interval2->format('%H:%I'); ?></td>
<td><?php echo $data['paintedStart']; ?></td>
<td><?php echo $interval3->format('%H:%I'); ?></td>
<td><?php echo $data['assemblyStart']; ?></td>
<td><?php echo $data['dateOn']; ?></td>
<td><?php echo $data['days']; ?></td>
<td><?php echo $data['dueDate']; ?></td>
</tr>   
<?php } ?>
</tbody>
</table>

Screenshot