If you use DateTime()
you can compare the two times and see if the stop time is in the past. If it is, display a different message. Also, this makes getting the interval between the two easier to get and display:
$now = new DateTime();
$stopdate = new DateTime($stopDate);
if ($stopdate > $now) {
$diff = $now->diff($stopTime);
echo $diff->format('%d days, %h hours, %i minutes, %s seconds');
echo " remaining to run " . $totalDistanceToDo . " meter";
}
else {
// negative time. display something else
}
Keep in mind if you don't want to display zero values for time units it will be a little more complex:
$now = new DateTime();
$stopdate = new DateTime($stopDate);
if ($stopdate > $now) {
$diff = $now->diff($stopTime);
if ($diff->d > 0) echo $diff->d . ' days, ';
if ($diff->h > 0) echo $diff->h . ' hours, ';
if ($diff->i > 0) echo $diff->i . ' minutes, ';
if ($diff->s > 0) echo $diff->s . ' seconds';
echo " remaining to run " . $totalDistanceToDo . " meter";
}
else {
// negative time. display something else
}