I've look for this, and there's some related questions, but no one gives me the answer I need. I have an entity with a date field and I need to select those who are older than 7 days from now:
$query = $repository->createQueryBuilder('rf')
->where('rf.sendDate >='.new \DateTime('-7 days'))
->getQuery();
I getting this error:
Catchable Fatal Error: Object of class DateTime could not be converted to string
What I wonder is why it assumes that rf.sendDate
is a string, when is defined as a DateTime objet in the entity? How I could compare this?
Any explanation really appreciated.
You should use parameters for this:
$query = $repository->createQueryBuilder('rf')
->where('rf.sendDate >= :ts')
->setParameter('ts', new \DateTime('-7 days'))
->getQuery();