通过月份得到本月有几天周末
程序员文章站
2022-03-27 15:28:01
CREATE FUNCTION getweekdayCount ( @month varchar(10)) RETURNS INT AS BEGIN--declare @month varchar(10)--set @month='201802' 通过月份得到本月有几天周末DECLARE @DAYC ......
CREATE FUNCTION getweekdayCount ( @month varchar(10))
RETURNS INT
AS
BEGIN
--declare @month varchar(10)
--set @month='201802'
---通过月份得到本月有几天周末
DECLARE @DAYCOUNT int
DECLARE @datestart datetime
DECLARE @dateend datetime
set @datestart =cast(SUBSTRING( @month,0,5)+'-'+SUBSTRING( @month,5,2)+'-01' as datetime)
set @dateend=dateadd(ms,-3,DATEADD(mm, DATEDIFF(m,0,@datestart)+1, 0))
SET @DAYCOUNT=0
while @datestart<=@dateend
begin
if(datename(weekday,@datestart)= '星期日' or datename(weekday,@datestart)='星期六') begin
set @DAYCOUNT=@DAYCOUNT+1
end
SET @DATESTART=DATEADD(DAY,1,@DATESTART)
end
RETURN(@DAYCOUNT)
END
上一篇: 品牌命名是捡现成的好还是自定义的好?
下一篇: 龙鲸河漂流门票多少钱 龙鲸河漂流门票