Calculate difference between 2 times in hours in PHP

后端 未结 7 730
無奈伤痛
無奈伤痛 2020-12-10 20:11

I have two times - For eg- the current time - 08:24 and date is 02/01/2013 in dd/mm/yyyy format and I have another time at 13:46 and date is 31/12/2012 . So, how can I cal

7条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-10 20:27

    Convert them both to timestamp values, and then subtract to get the difference in seconds.

    $ts1 = strtotime(str_replace('/', '-', '02/01/2013 08:24'));
    $ts2 = strtotime(str_replace('/', '-', '31/12/2012 13:46'));
    $diff = abs($ts1 - $ts2) / 3600;
    

提交回复
热议问题