Comparison between dates is not working

0

I searched right here and found a workaround for comparing dates, but for me it is not working at 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 9/15/2018 and dataAtual is 18/09/2018, so it is smaller and should enter if , but it does not enter.

    
asked by anonymous 18.09.2018 / 23:03

1 answer

0

The strtotime function recognizes American date formats (usually MM / DD / YYYY) so converting directly from DD / MM / YYYY may 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
}
    
18.09.2018 / 23:10