-1

I have two variables (which i'm getting from database):

$start = '07:14:10';
$end = '07:14:58';

I need to get the difference between these.

I think the answer could be 00:00:48.

Jhonatan Sandoval
  • 1,283
  • 6
  • 24
  • 40

2 Answers2

6

Using Datetime::diff this could be done.

$datetime1 = new DateTime('07:14:10');
$datetime2 = new DateTime('07:14:58');
$interval = $datetime1->diff($datetime2);

Here $interval will be the object in the form

DateInterval Object ( 
         [y] => 0 
         [m] => 0 
         [d] => 0 
         [h] => 0 
         [i] => 0 
         [s] => 48 
         [invert] => 0 
         [days] => 0 
     ) 

And can find out all the values

Abhik Chakraborty
  • 44,654
  • 6
  • 52
  • 63
1

Please have a look at strtotime.

In your case

echo strtotime('07:14:58')-strtotime('07:14:10');

will work.

RiWe
  • 367
  • 3
  • 9