Data range query not retuning all results till 23:59:59

In my Symfony project I have problem with results that are returning from this query builder in Doctrine.

When I input the date range from like "2020-01-03" to "2020-03-03" I got like results from March first and from March second and the result from 03. are missing. I need to add like :

$toDate = new DateTime('last day of this month 23:59:59')

so it includes all results to the end of that specific day.

 public function getReports($fromDate, $toDate)

    $query = $this->entityManager->getRepository(Report::class)
        ->orderBy('ur.reportDate', 'ASC');
    $this->handleRangeFilter($query, $fromDate, $toDate);

    return $query->getQuery()->getResult();

private function handleRangeFilter($query, $fromDate, $toDate)
    if($fromDate) {
            ->andWhere('ur.reportDate >= :startDate')
            ->setParameter('startDate', $fromDate);

    if($toDate) {
            ->andWhere('ur.reportDate <= :endDate')
            ->setParameter('endDate', $toDate);

I don’t know what should be modified here so I can get wanted result? Code works except that one part when the result from the last day which is inputed as a param is not returned.

When I input from March 1 to March 10, it returns all results till March 9..

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

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