-4

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.

Mahfuzul Alam
  • 3,057
  • 14
  • 15
J.Alan
  • 85
  • 1
  • 2
  • 12
  • http://php.net/manual/fr/function.date-diff.php – Frankich Feb 01 '17 at 10:12
  • checkout this : [How to get time difference in minutes in PHP](http://stackoverflow.com/questions/365191/how-to-get-time-difference-in-minutes-in-php) – hassan Feb 01 '17 at 10:13
  • 4
    Possible duplicate of [How to get time difference in minutes in PHP](http://stackoverflow.com/questions/365191/how-to-get-time-difference-in-minutes-in-php) – Amruth ls Feb 01 '17 at 10:15

2 Answers2

1

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.

Mahfuzul Alam
  • 3,057
  • 14
  • 15
-1

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;
?>
Gorakh Yadav
  • 304
  • 5
  • 19
  • 1
    If you are using other answers on SO to post all or part of your answer, please add reference to the original answer! – EhsanT Feb 01 '17 at 12:48