How to get time difference in minutes in PHP

后端 未结 17 2280
独厮守ぢ
独厮守ぢ 2020-11-21 07:22

How to calculate minute difference between two date-times in PHP?

17条回答
  •  不思量自难忘°
    2020-11-21 08:02

    I found so many solution but I never got correct solution. But i have created some code to find minutes please check it.

    = $mins1) {
            $mins = $mins2 - $mins1;
        }
        else {
          $mins = ($mins2 + 60) - $mins1;
          $hours--;
        }
        if($mins < 9)
        {
          $mins = str_pad($mins, 2, '0', STR_PAD_LEFT);
        }
        if($hours < 9)
        {
          $hours =str_pad($hours, 2, '0', STR_PAD_LEFT);
        }
    echo $hours.':'.$mins;
    ?>
    

    It gives output in hours and minutes for example 01 hour 02 minutes like 01:02

提交回复
热议问题