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

Asked

Viewed 206 times

1

I have to check if the user has registered an expiration date, if yes, I check if that date is lower 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 be ?

  • You are called two where one of them would not be a oror and?

  • Yeah, I don’t know how to do that on Doctrine, I tried to go underneath the Where a ->AND, or the side of the first Where() AND, but it also didn’t roll

1 answer

1

I will assume that you are passing the current date through the parameter $date, 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();
  • '$data = date("Y-m-d") $this->noticia = Doctrine::getTable('Noticias')->createQuery(’s') ->select(’s.*') ->Where("situation = ?", 'active') ->Where("data_validity < :date") ->orderby('data_cadastre desc') ->limit(5) // temp ->execute();'

  • but it wasn’t here

  • Missed putting the setParameter in order to put the date in the parameter data.

  • um, I tested it again, but it wasn’t, that my 'data_validity' in the database it is a data of type Date, I changed the setParameter there to ->format('Y-m-d') but also it wasn’t :/

  • Try to pass the object directly \DateTime, without calling method format.

  • A tip: keep an eye on the Doctrine queries log to see what query it is doing in your database.

Show 2 more comments

Browser other questions tagged

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