Do not display expired expiration banner banner

1

I'm trying to show on my site banner's that are not expired due date, I have in my bank a banner with the following dates:

The current date is: 2015-02-07

Expiry date: 2015-02-08

The script I wrote looks like this:

 
<?php if ($totalRows_rsBanner > 0) {  ?>
<?php do {
            $imagem = substr($row_rsBanner['imagem'],3);
            $url = $row_rsBanner['url'];

            $DataAtual = date("Y-m-d"); // data atual
            $timestamp_DataAtual = strtotime($DataAtual); // converte para timestamp Unix

            $DataExpiracao = $row_rsBanner['data_expiracao']; // data de expiração do anúncio
            $timestamp_DataExpiracao = strtotime($DataExpiracao); // converte para timestamp Unix

?>
            <?php if ($timestamp_DataAtual > $timestamp_DataExpiracao){ ?>
               <li><a href="<?php echo $url; ?>"><img src="<?php echo $imagem; ?>"></a></li>
            <?php } ?>
            <?php } while ($row_rsBanner = mysql_fetch_assoc($rsBanner)); ?>
<?php } ?>

The field of data_expiracao is in the format Date .

    
asked by anonymous 08.02.2015 / 00:04

1 answer

2

Your comparison sign was reversed.

One more tip: use the \DateTime object to work with the dates. This makes it easier to compare dates.

<?php

if ($totalRows_rsBanner > 0) {
    do {
        $imagem        = substr($row_rsBanner['imagem'],3);
        $url           = $row_rsBanner['url'];
        $DataAtual     = new \DateTime(); // sem argumentos = data atual
        $DataExpiracao = new \DateTime($row_rsBanner['data_expiracao']); // data de expiração do anúncio
        if ($DataAtual < $DataExpiracao) { ?>
            <li><a href="<?php echo $url; ?>"><img src="<?php echo $imagem; ?>"></a></li>
        <?php }
    } while ($row_rsBanner = mysql_fetch_assoc($rsBanner));
}
    
08.02.2015 / 00:38