[英]Comparing dates in mysql / symfony2
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:
我有一个带有日期字段的实体,我需要选择从现在起7天以上的实体:
$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? 我想知道的是,当在实体
rf.sendDate
定义为DateTime对象时,为什么假设rf.sendDate
是字符串? 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();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.