Calculate difference between 2 times in hours in PHP

后端 未结 7 709
無奈伤痛
無奈伤痛 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:30

    I found this is simplest way to find time difference, it always works for me

    $timestamp1 = strtotime(date('Y-m-d H:i'));
    $timestamp2 = strtotime("2020-04-05 18:00");
    
      $diff = abs($timestamp2 - $timestamp1)/(60*60);
    echo $diff;
    

提交回复
热议问题