SQL DateDiff - 当一个日期字段比另一个日期字段早2个月时返回行

时间:2016-03-21 21:30:37

标签: sql date

每一行都有一个BookedMonth和一个ReportingMonth。我想返回ReportingMonth比BookedMonth大2个月的行。

ReportingMonth      BookedMonth
2016-01-01 00:00:00 2015-11-01 00:00:00
2016-01-01 00:00:00 2015-12-01 00:00:00
2016-01-01 00:00:00 2016-01-01 00:00:00

WHERE

DATEDIFF,BookedMonth,ReportingMonth,2

1 个答案:

答案 0 :(得分:0)

类似的东西:

select * from table where datediff(month, ReportingMonth, BookedMonth) > 2;

修改

或者更好......请在下面发表评论:

select * from table where ReportingMonth > dateadd(month, 2, BookedMonth);