How can I get the difference of a time.
Let's say the first time value is this:
00:01:00
and the second one is this:
00:03:00
How can I get the difference with the same format.
How can I get the difference of a time.
Let's say the first time value is this:
00:01:00
and the second one is this:
00:03:00
How can I get the difference with the same format.
Try this one
$startTime = new DateTime("00:01:00");
$endTime = new DateTime("00:03:00");
$interval = $startTime->diff($endTime);
echo $interval->format('%H:%I:%S');
Outputs:
00:02:00
As you asked you wants it to be in same format.
Use like this its work for me
$to_time = strtotime("2008-12-13 10:42:00");
$from_time = strtotime("2008-12-13 10:21:00");
echo round(abs($to_time - $from_time) / 60,2). " minute";
u can also do this
<?php
$date1 = time();
sleep(2000);
$date2 = time();
$mins = ($date2 - $date1) / 60;
echo $mins;
?>