$em = $this->getEntityManager();
$query = $em->createQuery(
"SELECT b
FROM AppBundle:Booking b
AND b.checkin IS NULL
AND b.bookingDate=CURRENT_DATE()"
);
我想看今天的预订,但我也想在bookindDate预订时间。那么如何比较datetime bookingDate和CURRENT_DATE()?
答案 0 :(得分:1)
您可以尝试以下DQL查询:
SELECT b
FROM AppBundle:Booking b
AND b.checkin IS NULL
AND b.bookingDate BETWEEN CURRENT_DATE() AND CURRENT_DATE()
检查here BETWEEN doctrine2函数的文档
希望这个帮助
答案 1 :(得分:0)
你可以使用
$date = new DateTime();
$em = $this->getEntityManager();
$query = $em->createQuery(
"SELECT b
FROM AppBundle:Booking b
AND b.checkin IS NULL
AND b.bookingDate=". $date->format('Y-m-d')
);
答案 2 :(得分:0)
$em = $this->getEntityManager();
$query = $em->createQuery(
"SELECT b
FROM AppBundle:Booking b
AND b.checkin IS NULL
AND b.bookingDate >= CURRENT_DATE()
AND b.bookingDate <= CURRENT_DATE()+1"
);
这项工作对我来说太容易了;)