sql server 判断日期当前月有多少天

时间:2021-09-15 04:53:49

declare @tm datetime

set @tm = CONVERT(datetime,'2013-3-12')
declare @days int
select @days = case when MONTH(@tm) in(1,3,5,7,8,10,12) then 31 when MONTH(@tm) in(4,6,9,11) then 30 when MONTH(@tm) =2 and YEAR(@tm)%4 !=0 then 28 when MONTH(@tm) =2 and YEAR(@tm)%4 =0 then 29 else 0 end
select @days