Create query with date range in doctrine 2.0

0

I'm trying to get the records that I have processed (DateTime) less than 2 days from the current date.

I'm starting from the following reasoning.

  public function obtemSolicitacoesAntigasParaDeletar($executar = true){

    $qb = $this->buscar(array(), false);

    $qb->Where('sol.processadoEm < :data');

    $params[':data'] = 'CURRENT_DATE() - INTERVAL 2 DAY';
    $qb->setParameters($params);

    return $executar === true ? $qb->getQuery()->getResult() : $qb;
}

But I'm noticing that it is not working accordingly, it returns me a record that does not satisfy this restriction.

In the SQL command this Query works, but in the doctrine it is not. Can anyone help me adjust this method?

Att. Felipe.

    
asked by anonymous 24.02.2016 / 15:21

1 answer

0

Dae Galera.

Well, I've found a way to accomplish this task.

The solution found was:

public function obtemSolicitacoesAntigasParaDeletar($executar = true){

    $dataAtual = new DateTime('now');
    $dataAtual->sub(new \DateInterval('P1D'));

    $qb = $this->buscar(array(), false);

    $qb->andWhere('sol.processadoEm < :data');

    $params[':data'] = $dataAtual;
    $qb->setParameters($params);

    return $executar === true ? $qb->getQuery()->getResult() : $qb;
}

You can close the search.

Vlw.

    
07.03.2016 / 21:53