douji2520 2010-09-21 18:54
浏览 62
已采纳

如何在PHP中找到两个日期之间的小时差异?

I have two dates, formated like "Y-m-d H:i:s". I need to compare these two dates and figure out the hour difference.

  • 写回答

9条回答 默认 最新

  • dongxie3681 2010-09-21 18:56
    关注

    You can convert them to timestamps and go from there:

    $hourdiff = round((strtotime($time1) - strtotime($time2))/3600, 1);
    

    Dividing by 3600 because there are 3600 seconds in one hour and using round() to avoid having a lot of decimal places.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(8条)

报告相同问题?