Datetime range won’t select specific date

  datetime, doctrine-orm, php, symfony, symfony4

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)
        ->orderBy('ur.invoiceDate', 'ASC');

    if($fromDate) {
            ->andWhere('t.invoiceDate >= :startDate')
            ->setParameter('startDate', new DateTime($fromDate));

    if($toDate) {
            ->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(

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

Here is an image: here

Source: Symfony Questions