DATEDIFF(MONTH, '1/1/2014', '12/31/2014') + 1
This will give me 12.
What if I do this:
DATEDIFF(MONTH, '1/1/2014', '12/30/2014') + 1
It should give me 11 point something. How do I go about getting the exact number of months between these two dates? This needs to work for any combination of dates (any month of the year for any year).
You could do the calculation yourself in the following way:
This calculates the
@deciMonthDiff
to be 11.935483870967.Of course you can "inline" this as much as you want in order to avoid all the middle declarations.
The idea is to calculate the total month diff, then subtract the relative part of the first & last month depending on the actual day.