I have the following MSSQL statements:
DECLARE @mydate DATETIME
SELECT @mydate = GETDATE()
SET @NEXT_MONTH_BEGIN = CONVERT(varchar(2), MONTH(dateadd(month,1,@mydate))) + '/1/' + CONVERT(varchar(4),YEAR(@mydate))
SET @NEXT_MONTH_END = DateAdd(month,1,@NEXT_MONTH_BEGIN) - 1
@NEXT_MONTH_BEGIN as 'NEXT MONTH BEGIN',
@NEXT_MONTH_END as 'NEXT MONTH END'
These execute PERFECTLY for calculating my "NEXT MONTH END" date. The only problem is...it does NOT work for '12-31-xxxx'...in that, for example, when 'mydate' is '12-31-2013', then the code will return '2013-01-31'. In other words, it will not change over to the next year. I have tested this with Leap Years, and all is good...except that one little glitch. What am I doing wrong? Please help!
Thanks in advance!...Mark