我想选择现在位于startDate和endDate之间的条目,但它不起作用,我对此查询没有错误
$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();
我已经更改了这样的查询,现在可以使用了:
$qb = $this->createQueryBuilder('c')
->Where(':now BETWEEN c.startDate AND c.endDate')
->setParameter('now', new \Datetime())
->orderBy('c.id', 'DESC');
return $qb->getQuery()->getResult();
答案 0 :(得分:2)
$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();