NicolaPez
NicolaPez

Reputation: 587

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()"
    );

I want to see the booking of today, but also i want to have the time of booking in bookindDate. So how to comparison datetime bookingDate with CURRENT_DATE() ?

Upvotes: 2

Views: 3542

Answers (3)

NicolaPez
NicolaPez

Reputation: 587

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

this work for me, too easy ;)

Upvotes: 0

Kaveh Yzd
Kaveh Yzd

Reputation: 117

yo can use

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

Upvotes: 0

Matteo
Matteo

Reputation: 39450

You can try the following DQL query:

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

Check here the doc for BETWEEN doctrine2 function

Hope this help

Upvotes: 1

Related Questions