Calculate number of hours between 2 dates in PHP

前端 未结 16 1344
轮回少年
轮回少年 2020-11-22 14:07

How do I calculate the difference between two dates in hours?

For example:

day1=2006-04-12 12:30:00
day2=2006-04-14 11:30:00

In thi

16条回答
  •  一个人的身影
    2020-11-22 14:58

    $day1 = "2006-04-12 12:30:00"
    $day1 = strtotime($day1);
    $day2 = "2006-04-14 11:30:00"
    $day2 = strtotime($day2);
    
    $diffHours = round(($day2 - $day1) / 3600);
    

    I guess strtotime() function accept this date format.

提交回复
热议问题