hous
hous

Reputation: 2679

Select entries where now between startDate and endDate

I'd like to select entries where now is between startDate and endDate but it it doesn't work and I have no error apears with this query

$qb = $this->createQueryBuilder('c')
        ->Where(':now BETWEEN :startDate AND :endDate')
        ->setParameter('startDate', 'c.startDate')
        ->setParameter('endDate', 'c.endDate')
        ->setParameter('now', new \Datetime())
        ->orderBy('c.id', 'DESC');

    return $qb->getQuery()->getResult();

I have changed the query like this and it works now:

$qb = $this->createQueryBuilder('c')
        ->Where(':now BETWEEN c.startDate AND c.endDate')
        ->setParameter('now', new \Datetime())
        ->orderBy('c.id', 'DESC');
return $qb->getQuery()->getResult();

Upvotes: 0

Views: 305

Answers (1)

Miro
Miro

Reputation: 1899

$repository = $this->getDoctrine()->getRepository('AppBundle:Product');

$qb = $repository->createQueryBuilder('c')
        ->where('c.startDate < :now')
        ->andWhere('c.endDate > :now')
        ->setParameter('now', new \Datetime())
        ->orderBy('c.id', 'DESC');

    return $qb->getQuery()->getResult();

Upvotes: 2

Related Questions