简体   繁体   中英

How to calculate Date Difference in hours and minutes using PHP?

I have this code and he calculate date diference and it's been good so far but I have problem, I want to subtract high number from lower and show value on negative and this code automatically find which number is higher I don't want that.

$to_time = strtotime("2012-10-25 10:42:00");
$from_time = strtotime("2012-10-26 10:21:00");
echo round(abs($to_time - $from_time) / 60,2). " minute";

尝试

echo round(($to_time - $from_time) / 60,2). " minute";

Try this

$to_time = strtotime("2012-10-25 10:42:00");
$from_time = strtotime("2012-10-26 10:21:00");
echo round(($to_time - $from_time)/60,2). " minute";

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM