使用 DATEDIFF() 获取特定月份之间的确切天数未给出预期结果

Get Exact Number of Days Between Certain Months Using DATEDIFF() Not Giving Expected Results

以下是示例数据:

NewReportDate | Age      | OldReportDate
-----------------------------------------
2014-04-28    |31.558767 | 2014-03-28
2014-04-28    |13-438767 | 2014-03-28
2014-04-28    |13.198767 | 2014-03-28

以下是我的查询:

SELECT 
Q.Type
,Q.Oper
,Q.SNo
,Q.Hours
,CONVERT(Date, Q.ReportDate + '28', 112) AS 'Report_Date'
, a.*
, (DATEDIFF(dy, CONVERT(Date, Q.ReportDate + '28', 112),A.ReportDate )/365) + A.age AS 'AdjustedAge'
FROM QReport Q
INNER JOIN AReport a
ON q.name = a.name 
WHERE a.ReportDate = '2014-03-28 00:00:00.000'
ORDER BY A.ReportDate desc

以下是我的结果:

NewReportDate | Age      | OldReportDate | AdjustedAge|
-------------------------------------------------------
2014-04-28    |31.558767 | 2014-03-28    |31.558767 
2014-04-28    |13.438767 | 2014-03-28    |13.438767
2014-04-28    |13.198767 | 2014-03-28    |13.198767 

NewReportDateOldReportDate 之间有一个月的差异时,为什么我的 AdjustedAge 没有改变?

小数点应该有区别

从2014-04-28到2014-03-28一共有31天

31 / 365 使用整数除法 = 0

0 + x = x

因此这两个值是相同的。考虑除以 365.26。