我想选择现在介于 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();
$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();