This article is half-done without your Comment! *** Please share your thoughts via Comment ***
Check the below input date and expected output to find the total number of days in the month of given date.
Input Date Date:
1 |
'2017-08-08' |
Expected Output:
1 2 3 |
NumberOfDays ------------ 31 |
Solution:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
DECLARE @InputDate DATE = '2017-08-08' SELECT CASE WHEN MONTH(@InputDate) IN (1, 3, 5, 7, 8, 10, 12) THEN 31 WHEN MONTH(@InputDate) IN (4, 6, 9, 11) THEN 30 ELSE CASE WHEN (YEAR(@InputDate) % 4 = 0 AND YEAR(@InputDate) % 100 != 0) OR (YEAR(@InputDate) % 400 = 0) THEN 29 ELSE 28 END END AS NumberOfDays |
Please try the different solution for this puzzle and share it via comment...