查询每个月有多少天
偶尔会用到,做个笔记:
DECLARE @currDate DATETIME SET @currDate = '2024-01-01' DECLARE @currDays INT SELECT @currDays = 32-DAY(@currDate-DAY(@currDate)+32) SELECT CONVERT(NVARCHAR(7),@currDate,23) 当前年月,@currDays 当前月对应的天数
用循环输出:
DECLARE @currDate DATETIME SET @currDate = '2024-01-01' DECLARE @currDays INT SELECT @currDays = 32-DAY(@currDate-DAY(@currDate)+32) SELECT CONVERT(NVARCHAR(7),@currDate,23) 当前年月,@currDays 当前月对应的天数 WHILE(@currDays>0) BEGIN PRINT @currDays SET @currDays = @currDays - 1 END
以上。
PS:转载请注明来源 https://www.cnblogs.com/sunshine-wy,疑问和勘误可在下方留言。