IMB IMB - 1 month ago 7
PHP Question

Find date_diff in minutes?

Can

date_diff
be used to compute difference in minutes?

$a = date_create('2016-11-03 00:00:00');
$b = date_create('2016-11-05 00:19:00');

$dd = date_diff($a, $b);
echo $dd->format('%i');


The above code will return
19 minutes
even if it's already been
2 days

Answer

Try this

it will output difference in minutes.

$a = new DateTime('2016-11-05 00:00:00');
$b = new DateTime('2016-11-05 00:19:00');
 $diff =  ($b->getTimestamp() - $a->getTimestamp())/60;
 echo $diff;