This is what I tried:
$time = date('Y/m/d');
$alerts = $repository->findBy(['datum' => $time]);
and
$time = date('Y/m/d');
$lessons = $repository->createQueryBuilder('q')
->where('q.datum LIKE currentDate')
->setParameter('currentDate', $time);
For some reason those don’t work and I have no idea why. It should be displaying the last one in a dd($lessons), but it doesn’t
Update:
This is what I got rn, but it’s still not working:
$today = new DateTime('today');
$tomorrow = new DateTime('today +1 day');
$lessons = $repository->createQueryBuilder('q')
->where('q.datum > :today')
->andWhere('q.datum < :tomorrow')
->setParameter('today', $today)
->setParameter('tomorrow', $tomorrow);
3
Answers
Why don’t you use the current database date function to perform this query? It would look like this:
Your checking the date format ‘Y/m/d’ (2023/05/11) with a saved date field format in the database ‘Y-m-d’ (2023-05-11)
Besides that your checking if you can find the current date but according to your database table there is no current date.
The other check that your doing is checking if there is a date higher then 2023-05-11 00:00:00, you should change this to higher and the same ‘>=’
i guess your entity date field is a datetime field (or at least a date field), when not, make sure it is, then you need to use the DateTime Object for searching
your entity field should look like this
your repo function can be look like this
using that funcion inside your controller
gl hf