避免在时间减法上获得负值Laravel php

I'm subtracting 2 different times and getting negative values, to explain it further here is my code:

        <td>{{date('l',strtotime($mydate->logon))}}</td>
        <td>{{date('jS F, Y',strtotime($mydate->logon))}}</td>
        <td>{{$date1=date('h:i A',strtotime($mydate->logon))}}</td>
        <td>{{$date2=date('h:i A',strtotime($mydate->logoff))}}</td>
        <td>{{$result=$date2-$date1}}</td>            
        <td>

The $result value sometimes goes negative because its somethimes subtracting pm and am. Any ways to avoid this? thanks