I want to substract two hours:
a. 40:00:00 b. 31:18:00
I want this result 09:42:00. How can i achieve this?
The result is 08:42:00 (40:00:00 - 31:18:00 = 08:42:00 not 09:42:00)
I think this solves:
$lasthour = '40:00:00';
$firsthour = '31:18:00';
//explode first hour
list($h, $m, $s) = explode(':', $firsthour);
//convert to seconds
$secFh = ($h * 3600 + $m * 60 + $s);
//explode last hour
list($h, $m, $s) = explode(':', $lasthour);
//convert to seconds
$secLh = ($h * 3600 + $m * 60 + $s);
$sub = $secLh - $secFh;
echo gmdate("H:i:s", $sub);
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.