0
$timein = date('h:i:s a',strtotime($jrow['time_in']));
$timeout = date('h:i:s a',strtotime($jrow['time_out']));
$diff    = $timeout - $timein;
echo "<td>".date('h:i:s', $diff)."</td>";

How can I get the difference between these two time values?

Christopher Creutzig
  • 8,656
  • 35
  • 45
kebong
  • 15
  • 3

1 Answers1

0

You can get the full time difference through the below function

function date_getFullTimeDifference( $start, $end )
{
$uts['start']      =    strtotime( $start );
        $uts['end']        =    strtotime( $end );
        if( $uts['start']!==-1 && $uts['end']!==-1 )
        {
            if( $uts['end'] >= $uts['start'] )
            {
                $diff    =    $uts['end'] - $uts['start'];
                if( $years=intval((floor($diff/31104000))) )
                    $diff = $diff % 31104000;
                if( $months=intval((floor($diff/2592000))) )
                    $diff = $diff % 2592000;
                if( $days=intval((floor($diff/86400))) )
                    $diff = $diff % 86400;
                if( $hours=intval((floor($diff/3600))) )
                    $diff = $diff % 3600;
                if( $minutes=intval((floor($diff/60))) )
                    $diff = $diff % 60;
                $diff    =    intval( $diff );
                return( array('years'=>$years,'months'=>$months,'days'=>$days, 'hours'=>$hours, 'minutes'=>$minutes, 'seconds'=>$diff) );
            }
            else
            {
                echo "Ending date/time is earlier than the start date/time";
            }
        }
        else
        {
            echo "Invalid date/time data detected";
        }
}
Veerendra
  • 2,562
  • 2
  • 22
  • 39