Code for comparison of dates

Asked

Viewed 37 times

0

I have a code that compares the current date with a specific date and checks if this "delivery" is delayed or expires today for example but even if it is the same date as the current Else does not appear "on time" it does not happen that can help me thank

$hoje = new DateTime();

echo $hoje->format("d/m/Y");

$entrega = new DateTime('2018-07-10');

echo "<br><br>";

if ($hoje > $entrega) {
    echo "Atrasado";
    echo "<br><br>";
    $interval = $hoje->diff($entrega);
    echo "$interval->days dias";

} else if ($hoje == $entrega) {
    echo "Vence hoje";
} else {
    echo "Em dia";
}
  • Put the interval out of the IF and compare if $interval = 0, > 0 and > 0 with "invert" - Note that in the "related" column on the right side of the site you have more posts on the subject (and if you use the search, you will find other)

  • why I saw that invert returns a boolean value and I didn’t find any questions that approached about counting the days

  • Kind of like this? $interval = $hoje->diff($delivery); if ($interval ->invert > 0) { echo "Delayed"; echo "<br><br>"; echo "$interval->days"; } Else if ($interval->invert === 0) { echo "Wins today"; } Else { echo "On time"; }

  • I don’t understand but thanks anyway

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.