SQL Fiddle from the following:
SELECT DATEDIFF(month,
CONVERT(VARCHAR(19),
CAST(MonthFROM as varchar) + '/01/' + CAST(YearFROM as varchar),
101),
CONVERT(VARCHAR(19),
CAST(MonthTo as varchar) + '/01/' + CAST(YearTO as varchar),
101)) + 1 AS MonthPast
FROM MyTable;
Result:
MONTHPAST
14
Actual difference of months 13, but you received 14as expected result. If your calculation was incorrect, and you really need to 13, then remove it + 1from the request.
source
share