简体   繁体   English

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

[英]SQL DateDiff - return row when one date field is 2 months older than another date field

Each row has a BookedMonth and a ReportingMonth. 每行都有一个BookedMonth和一个ReportingMonth。 I want to return the rows where the ReportingMonth is 2 Months greater than the BookedMonth. 我想返回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

Something like: 就像是:

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

EDIT 编辑

Or better... se comments here below: 或更好...下面的se评论:

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

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM