如何将日期时间与 DQL 的 CURRENT_DATE() 进行比较

How to comparison datetime with CURRENT_DATE() of DQL

$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() 呢?

您可以尝试以下 DQL 查询:

SELECT b
        FROM AppBundle:Booking b
        AND b.checkin IS NULL
        AND b.bookingDate BETWEEN CURRENT_DATE() AND CURRENT_DATE()

检查here BETWEEN doctrine2 函数的文档

希望对您有所帮助

你可以使用

$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')
    );
$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"
    );

这对我来说太简单了;)