How do I subtract two times in PHP?
There is a known time format of 2012-11-22 12:05:07 I want to use the current time format is: 2012-11-23 16:13:08 minus the first time, that is, 2012-11-23 16:13:08 minus 2012-11-22 12:05:07 the time spent 1 days, 4 hours, 8 minutes, 1 seconds.
------Solution--------------------
$time = Time ()-strtotime (' 2012-11-22 12:00:00 ');
$yourday = (int) ($time/(3600*24));
$yourhour = (int) (($time% (3600*24))/(3600));
$yourmin = (int) ($time% (3600)/60);
echo $yourday. ' Day ' $yourhour. ' Hours ' $yourmin. ' Minutes ';
1 days, 4 hours, 34 minutes
------Solution--------------------
$datetime 1 = new DateTime (' 2012-11-23 16:13:08 ');
$datetime 2 = new DateTime (' 2012-11-22 12:05:07 ');
$interval = $datetime 1->diff ($datetime 2);
echo $interval->format ('%d days%h hours%i minutes%s seconds ');
1 days, 04 hours, 8 minutes, 1 seconds