Create query with date range in Doctrine 2.0

Asked

Viewed 90 times

0

I’m trying to get the records that are processed No (Datetime) less than 2 days from the current date.

I am 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 am realizing that it is not working accordingly, it returns me record that do not satisfy this restriction.

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

Att. Felipe.

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;
}

Can close the theme.

Vlw.

  • There is no concept of "close topic" here. It is you who has to validate your own answer.

Browser other questions tagged

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