Quantcast
Channel: Active questions tagged symfony4 - Stack Overflow
Viewing all articles
Browse latest Browse all 3924

Datetime range won't select specific date

$
0
0

I have a method to return results from db from startDate to endDate passing in like parameters in postman.

Everything seems to be working fine but it returns all results from database.

I think that problem could be with parameters..

public function getInvoices($fromDate = null, $toDate = null){    $query = $this->entityManager->getRepository(Invoice::class)        ->createQueryBuilder('ur')        ->select('ur')        ->orderBy('ur.invoiceDate', 'ASC');    if($fromDate) {        $query            ->andWhere('t.invoiceDate >= :startDate')            ->setParameter('startDate', new \DateTime($fromDate));    }    if($toDate) {        $query            ->andWhere('t.invoiceDate <= :endDate')            ->setParameter('endDate', new \DateTime($toDate));    }    return $query->getQuery()->getResult();}

And I am calling this method in my controller like:

$data = [];$responseData = $this->invoiceService->getInvoices(        @$this->data['startDate'],        @$this->data['endDate']    );

I pass this two parameters via postman and it returns all results:

Here is an image: here


Viewing all articles
Browse latest Browse all 3924

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>