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
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;
You can use DateTime()
Get difference in hour , minute , and seconds
$a = new \DateTime("2016-11-05 00:00:00");
$b = new \DateTime("2016-11-05 00:19:00");
$dateinterval = $b->diff($a);
$time = sprintf(
'%d:%02d:%02d',
($dateinterval->d * 24) + $dateinterval->h,
$dateinterval->i,
$dateinterval->s
);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.