finding out difference between two times

前端 未结 7 1969
醉话见心
醉话见心 2021-01-14 04:03

I wrote the following code to determine the amount of time that employees spend on a task:

$time1 = $row_TicketRS[\'OpenTime\'];
$time2= $row_TicketRS[\'Clos         


        
7条回答
  •  遥遥无期
    2021-01-14 04:38

    function getTimeDiff($dtime,$atime)
    {
        $nextDay=$dtime>$atime?1:0;
        $dep=explode(':',$dtime);
        $arr=explode(':',$atime);
    
    
        $diff=abs(mktime($dep[0],$dep[1],0,date('n'),date('j'),date('y'))-mktime($arr[0],$arr[1],0,date('n'),date('j')+$nextDay,date('y')));
    
        //Hour
    
        $hours=floor($diff/(60*60));
    
        //Minute 
    
        $mins=floor(($diff-($hours*60*60))/(60));
    
        //Second
    
        $secs=floor(($diff-(($hours*60*60)+($mins*60))));
    
        if(strlen($hours)<2)
        {
            $hours="0".$hours;
        }
    
        if(strlen($mins)<2)
        {
            $mins="0".$mins;
        }
    
        if(strlen($secs)<2)
        {
            $secs="0".$secs;
        }
    
        return $hours.':'.$mins.':'.$secs;
    
    }
    
    echo getTimeDiff("23:30","01:30");
    

提交回复
热议问题