/ Published in: SQL

Input: Month and year number
Output: Last day of month
Output: Last day of month
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
DECLARE @StringDate VARCHAR(20) -- string variable used to hold date in string format DECLARE @StringDay VARCHAR(2) -- string variable used to hold day number -- work out what the last day of the month is SELECT @StringDay= CASE WHEN @MonthNumber IN(1, 3, 5, 7, 8, 10, 12) THEN 31 WHEN @MonthNumber IN(4, 6, 9, 11) THEN 30 ELSE 29 END BEGIN TRY SET @StringDate=@YearNumber + '-' + '02-' + @StringDay SET @StartDate = CONVERT(DateTime, @StringDate) END TRY BEGIN CATCH SET @StringDay='28' END CATCH
Comments
