phpdatetimedoctrine-ormcomparisondoctrine-dbal

I'm using doctrine orm and I want to compare the date(only) from a datetime column in the database to user inputted date (only)datetime-local in php


I have an entity with a due-date column saving datetime. I want to confirm that the date(alone) has not been saved before. But I'm unable to compare just the dates from the datetime objects. The datetime from the database repo and the datetime-local input from the user

I have tried

$entityManager->getRepository (entity::class)->count('due_date', $userInputedDate);

But this doesn't return true unless the time part is also exactly the same. I want to be able to compare only the dates without the time.

I also read up about the mysql DATE() function but I don't know how to apply it with doctrine orm (entity) manager.

Also thought about pulling the due_date column, looping over it , formatting only the date to string and then comparing the userInputed date(only) part. But it seems like it will be inefficient for a check that should happen before form is submitted.


Solution

  • You can use DQL (instead of getRepository()) for this, with the Doctrine Extensions package to provide the DATE function