You're basically trying to subtract two strings. If you echo $from_time
, you can find out that the value will be something like 2013-10-27 12:49:270
, and $to_time
will be another string -- 2013-10-27 13:28:01
.
You need to convert them into timestamps before doing the substraction:
$from_time = time();
$to_time = strtotime($row['clock']);
I recommend using the DateTime
class for working with dates and times.
This is how you find the difference between two dates using DateTime
class:
$from_time = new DateTime('now');
$to_time = new DateTime("2013-10-27 13:28:01");
$interval = $from_time->diff($to_time);
echo $interval->format('%h hours %i minutes %S seconds');
Output:
0 hours 31 minutes 48 seconds