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.本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报