Subtract time in PHP

前端 未结 3 1894
名媛妹妹
名媛妹妹 2020-11-27 22:15

I have been looking for an answer for a few hours now, but I can\'t find one.

I\'m writing a simple script. The user sets their work start and end time.

3条回答
  •  半阙折子戏
    2020-11-27 22:32

    A bit nicer is the following:

    
    $a = new DateTime('08:00');
    $b = new DateTime('16:00');
    $interval = $a->diff($b);
    
    echo $interval->format("%H");
    
    

    That will give you the difference in hours.

提交回复
热议问题