Home:ALL Converter>Doctrine Datetime and where condition

Doctrine Datetime and where condition

Ask Time:2013-06-07T15:23:04         Author:DonOfDen

Json Formatter

I am writing a Doctrine 2.3 Query and I am facing some issues:

The SQL Query which I am reflecting was:

SELECT * 
FROM  `entry` 
WHERE  `plate` LIKE  '%'
AND  `recognition_datetime` BETWEEN '2013-03-13 22:20:18'
AND  '2013-03-13 22:20:20';

I am getting the out put with the rows selected.

Doctrine which I am trying:

Opt 1:

$qry = $this->manager()->createQueryBuilder()
                    ->from($this->entity, 'e')
                    ->select('e');
$qry->where('e.plate like :plate');
$qry->setParameter('plate', $plate);
$qry->add('where', "e.datetime between '2013-03-13 22:20:18' and '2013-03-13 22:20:20'");
$qry->setMaxResults( $limit );

It out puts only the first where condition:

SELECT e FROM Myproject\Domain\result e WHERE e.plate like '%'

Opt 2:

$qry = $this->manager()->createQueryBuilder()
                    ->from($this->entity, 'e')
                    ->select('e');
$qry->where('e.plate like :plate');
$qry->setParameter('plate', $plate);
$qry->andWhere('e.datetime BETWEEN :monday AND :sunday')
   ->setParameter('monday', $fromdate->format('Y-m-d H:i:s'))
   ->setParameter('sunday', $todate->format('Y-m-d H:i:s'));

It prints only the second where as query. Can some one help me how to write multiple where/And/or condition?

Author:DonOfDen,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/16978443/doctrine-datetime-and-where-condition
yy