Comparison between dates is not working

Asked

Viewed 22 times

0

I searched right here and found a solution to compare dates, but for me it is not working to strtotime

$dataVencimento = date("d/m/Y", strtotime($dados->VENCIMENTO));
 $dataAtual = date("d/m/Y");
 echo $dataAtual;
 if(strtotime($dataVencimento) < strtotime($dataAtual))
 {
        $situacao =  "<span class='label label-danger'>VENCIDO</span>";
 }

The value of dataVencimento is 15/09/2018 and the dataAtual is 18/09/2018, therefore it is smaller and should enter the if, but does not enter.

  • believe q this link can help you https://stackoverflow.com/questions/8722806/how-to-compartwo-dates-in-php

1 answer

0


The function strtotime recognizes American date formats (usually MM/DD/YYYY) so converting directly from DD/MM/YYYY can cause problems.

What you can do is compare two date objects that are returned by strtotime using a pattern recognized as AAAA-MM-DD:

$dataVencimento = strtotime($dados->VENCIMENTO);
$dataAtual = date("Y-m-d");

if($dataVencimento < strtotime($dataAtual)) {
    // Vencido
}

Browser other questions tagged

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