请参考以下示例,并请告诉我您的想法。
declare @EmployeeStartDate datetime='01-Sep-2013' declare @EmployeeEndDate datetime='15-Nov-2013' select DateDiff(mm,@EmployeeStartDate, DateAdd(mm, 1,@EmployeeEndDate))
输出=3 预期输出=2.5
3
2.5
由于我在十一月只有15天,所以我应该去0.5十一月
0.5
试试这个
SELECT CASE WHEN DATEDIFF(d,'2013-09-01', '2013-11-15')>30 THEN DATEDIFF(d,'2013-09-01', '2013-11-15')/30.0 ELSE 0 END AS 'MonthDifference'
或者
SELECT DATEDIFF(DAY, '2013-09-01', '2013-11-15') / 30.436875E