Number of days left in a given month How do I find the number of days left in the current month? Example if current month is November and todays date is 16/11/2016 The Numb
Since this is sql server 2008 you can't use EOMonth (that was introduced in 2012 version).
You have to do some date adds and date diffs:
SELECT DATEDIFF(DAY,
GETDATE(),
DATEADD(MONTH,
1,
DATEADD(DAY, 1 - DAY(GETDATE()), GETDATE())
)
) - 1
explanations:
DATEADD(DAY, 1 - DAY(GETDATE()), GETDATE())
gets the first day of the current month, the wrapping DATEADD
adds one month, and the wrapping DATEDIFF
returns the number of days between the current date and the first date of the next month. This is why you need to subtruct 1 to get the correct number of days.