I have 2 dates in the code, and I have to calculate the remaining time, I've already done that, but when this value is negative (the date has already been passed), I still show the value without the (-) sign. That's a problem because I need to verify if this time has passed or not yet.
This is the code used:
// AQUÍ SE LE DA FORMATO A LA FECHA
function format_interval(DateInterval $interval) {
$result = "";
if ($interval->y) { $result .= $interval->format("%y years "); }
if ($interval->m) { $result .= $interval->format("%m months "); }
if ($interval->d) { $result .= $interval->format("%d days "); }
if ($interval->h) { $result .= $interval->format("%h hours "); }
if ($interval->i) { $result .= $interval->format("%i min. "); }
if ($interval->s) { $result .= $interval->format("%s seconds "); }
return $result;
}
$first_date = new DateTime("$endDate"); // PRIMERA FECHA
$second_date = new DateTime("$curDate"); //SEGUNDA FECHA
$difference = $first_date->diff($second_date);