简体   繁体   English

教义2.如何在querybuilder中计算两个日期时间字段之间的差异

[英]Doctrine 2. How to calculate difference between two datetime fields in querybuilder

I have to following tables: 我必须下表:

Registration
    id int
    created datetime

Activity
    id int
    startdate datetime

Now I want to add this condition to my SQL query: 现在,我想将此条件添加到我的SQL查询中:

(Registration.created + 7 days) <= Activity.startdate

How can I do this in Doctrine 2? 我该如何在教义2中做到这一点? I prefer a database independent solution. 我更喜欢独立于数据库的解决方案。

DATE_SUB was the solution. 解决方法是DATE_SUB。 I used it with doctrine 2.1. 我将其与教义2.1一起使用。

$EntityManager->createQueryBuilder()->expr()->gte("r.created", "DATE_SUB(a.startDate, 7, 'day')")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 计算不包括周末的两个日期时间之间的差异 - Calculate difference between two datetime excluding weekends doctrine2 querybuilder不之间 - doctrine2 querybuilder not between 删除日期,从今天起相差两天-Doctrine,QueryBuilder - deleting dates with difference of two days from today - Doctrine, QueryBuilder 学问querybuilder获取最近的日期时间 - doctrine querybuilder get nearest datetime 如何计算两个日期时间秒之间的差异? - how to calculate the different between two datetime on seconds? 如何使用 QueryBuilder 计算 CURRENT_DATE() 与上个月之间的天数差异? - How to calculate the difference in days between CURRENT_DATE() and the last month with QueryBuilder? 计算MySQL表中两个时间字段之间的时差 - Calculate difference between two time fields in MySQL table 如何在没有关系表的情况下使用两个实体之间的QueryBuilder在Symfony Doctrine中加入 - How to JOIN without relational table in Symfony Doctrine with QueryBuilder between 2 entities 如何 select doctrine querybuilder 与 symfony 中的表之间的特定连接? - How to select a specific connection between tables in doctrine querybuilder with symfony? 如何从HTTPResponseMessage解析PHP Doctrine Querybuilder DateTime到C#DateTime? - How to parse PHP Doctrine Querybuilder DateTime from a HTTPResponseMessage to C# DateTime?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM