tutorials, tips and tricks to design a Sql Server, Cloud Service . Micrsoft Interview Question
Friday, January 21, 2011
How to get number of days in a month
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
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment