How to check if a table date is lower than today's date in Doctrine - Postgresql

1

I have to check if the user has registered an expiration date, if yes, check if that date is less than today if it is, it shows if it does not hide, I did so:

        $this->noticia = Doctrine::getTable('Noticias')->createQuery('s')
            ->select('s.*')
                    ->where("situacao = ?", 'ativo')
                    ->where("data_validade < ", 'date("Y-m-d")') 
              // tentei dessa maneira tambem
              // criei uma variavel la em cima no escopo ++ $data = date("Y-m-d");
             // e chamei ela assim(embaixo) 
             // ->where("data_validade < ") . $data
            ->orderBy('data_cadastro desc')
            //->limit(5) // temp
            ->execute();

but in the browser, the page is all blank and no error appears. Hmm. What can it be ?

    
asked by anonymous 27.03.2015 / 18:28

1 answer

1

I'll assume you're passing the current date using the $date parameter, which is a \DateTime . Your query would look like this:

$this->noticia = Doctrine::getTable('Noticias')->createQuery('s')
    ->select('s.*')
    ->where("situacao = 'ativo'")
    ->where('data_validade < :data')
    ->orderBy('data_cadastro desc')
    ->setParameter('data', $data->format('Y-m-d H:i:s'))
    ->execute();
    
27.03.2015 / 18:40