Query results for current day between two dates [duplicate]

In my Symfony project, I wrote Doctrine query where I am trying to return results of specific date range.

I have table fields startDate and endDate and I am trying to return only results where today’s date is between these two..

I will post my try here:

public function check()
{
    $now = new DateTime();
    return $this->getByDate($now);
}

public function getBetweenDate(Datetime $date)
{
    $from = new DateTime($date->format("Y-m-d")." 00:00:00");
    $to   = new DateTime($date->format("Y-m-d")." 23:59:59");

    $qb = $this->createQueryBuilder("e");
    $qb
        ->where('CURRENT_DATE() BETWEEN :startDate AND :endDate')
        ->setParameter('startDate', $from)
        ->setParameter('endDate', $to);
    ;
    $result = $qb->getQuery()->getResult();

    return $result;
}

This method returns all results I inputed.. What am I doing wrong?

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *