I have a filter bar where you can search with names, and vehicule brand but I wanted to know how to actually check with dates in this format -> dd/mm/yyyy as right know nothing happens when I search a date, I receive a blank page without errors, but just zero results.
I found maybe a solution using this $fullDate = DateTime::createFromFormat('d/m/Y',$filter); but i have a struggle where to add it in my code.
So I will share you my code and what I researched
The query where you can see all queries with the filter arguments (for my search)
public function getQueryByTypeAndPro($type, User $user, $archive, $filter)
{
$fullDate = \DateTime::createFromFormat('d/m/Y', $filter);
$qb = $this->createQueryBuilder("opn");
$or = new Orx();
if($fullDate !== false) {
$textFilters[] = $qb->expr()->orx($qb->expr()->like('opn.dateCreation', ':filter'));
} else {
$textFilters[] = $qb->expr()->orx($qb->expr()->like('opn.id', ':filter'));
$textFilters[] = $qb->expr()->orx($qb->expr()->like('opn.vehiculeMarque', ':filter'));
$textFilters[] = $qb->expr()->orx($qb->expr()->like('opn.clientNom', ':filter'));
$textFilters[] = $qb->expr()->orx($qb->expr()->like('opn.clientPrenom', ':filter'));
}
$or->addMultiple($textFilters);
$qb->andWhere($or);
$query = $qb
->andWhere("opn.type = :type")
->andWhere("opn.resellerId = :reseller")
->andWhere("opn.archive = :archive")
->setParameters([
"type" => $type,
"reseller" => $user->getId(),
'archive' => $archive,
'filter' => '%' . $filter . '%'
])
->orderBy("opn.dateCreation", "DESC")
->getQuery()
;
return $query;
}
This is what it shows me in my query profiler when I do a date search in this format dd/mm/yyyy
SELECT
count(r0_.id) AS sclr0
FROM
reseller_operation r0_
WHERE
r0_.dateCreation LIKE ?
AND r0_.type = ?
AND r0_.reseller_id = ?
AND r0_.archive = ?
So right now at that moment this code work in a way that when I do a dump dump($fullDate) it shows false when I don't enter a date, and shows the date when I do. So I guess that does work at the moment.
The problem i still have is that it doesn't show any results, just a blank page with zero results.
I don't know if you need my controller or my twig to get a better picture? I didn't put them in here because I thought this wouldn't be necessary, but feel free to ask me.