嘿,我有一个关于querybuilder的问题。
我在EntityRepository
中此代码在from和to
之间找到所有内容public function getBySpan($from,$to)
{
$from = new \DateTime($from->format("Y-m-d")." 00:00:00");
$to = new \DateTime($to->format("Y-m-d")." 23:30:00");
$qb = $this->createQueryBuilder("e");
$qb
->andWhere('e.date BETWEEN :from AND :to')
->setParameter('from', $from )
->setParameter('to', $to)
;
$result = $qb->getQuery()->getResult();
return $result;
}
我试图获得的是找到所有$ date在e.from AND e.to
之间的地方 public function getByDate($date)
{
$date = new \DateTime($date->format("Y-m-d")." 00:05:50");
$qb = $this->createQueryBuilder("e");
$qb
/* HOW TO PUT THIS LINE TO WORK ? */
->andWhere(':date BETWEEN e.from AND e.to')
->setParameter('date', $date)
;
$result = $qb->getQuery()->getResult();
return $result;
}
提前感谢任何帮助
答案 0 :(得分:1)
我对这个查询构建器不太熟悉,但您可以尝试这样的
->andWhere('e.from <= :date')
->andWhere('e.to >= :date')
->setParameter('date', $date);
这与你想要达到的目标类似。