DECLARE @InputPeriodStart DATE = '1/1/2014'
DECLARE @InputPeriodEnd DATE = '12/31/2014'
ROUND(CONVERT(DECIMAL, DATEDIFF(dd, @InputPeriodStart, @InputPeriodEnd)) / 30, 1) AS DECIMAL(18, 2))
The issue here is that not every month has 30 days in it. So how can I make this calculation work properly?
I would need to remove the ROUND()
and then replace the 30 with the actual number of days for each month. I'm not sure how I'd do that.
Is this what you're looking for?
If you are trying to do something a bit weirder like adjust for the days in the month your "periodstart" is in - then you are getting into some weird territory but it is still possible. Just drop a comment to specify.
Edit:
take a look at this SQLFiddle:
http://sqlfiddle.com/#!6/a1463/7
This achieves what my last comment lays out.