SQL
How to get number of days in a month
By
Friday, January 21, 2011
comments
React:
select CASE WHEN MONTH(getdate()) IN (1, 3, 5, 7, 8, 10, 12) THEN 31 WHEN MONTH(getdate()) IN (4, 6, 9, 11) THEN 30 ELSE CASE WHEN (YEAR(getdate()) % 4 = 0 AND YEAR(getdate()) % 100 != 0) OR (YEAR(getdate()) % 400 = 0) THEN 29 ELSE 28 END end
Suthahar Jegatheesan
Cloud, AI & Mobile Solutions Architect · 18+ years across Azure, Google Cloud and Firebase, C#, Python, .NET MAUI and Flutter. Author of the Xamarin Q&A Book.
More in this series
Related articles
No comments: