-- ============================================= -- Author: LJB -- Create date:2019年3月19日14:29:23 -- Description: 获取工作日 -- ============================================= CREATE FUNCTION [dbo].[f_GetWorkday](@bdate DATETIME, @edate DATETIME,@workDayEnum INT) RETURNS INT AS BEGIN DECLARE @workdays INT; DECLARE @saturdayCount INT; IF(@edate <= CONVERT(datetime,'1900-01-01')) SET @edate = GETDATE(); IF(@workDayEnum = 1) --周六、周日休息 BEGIN SET @workdays = 0; END ELSE IF(@workDayEnum = 2) --周六、周日不休息 BEGIN SET @workdays = DATEDIFF(day,@bdate,@edate) + 1; RETURN @workdays; END ELSE --周六不休息 BEGIN SET @workdays = datediff(wk,@bdate,@edate);--两个时间内有多少个周六 END --一周5个工作日计算 while DATEDIFF(d, @bdate, @edate) >= 0 begin if datepart(dw,@bdate) > 1 and datepart(dw,@bdate) < 7 begin select @workdays=@workdays+1 end select @bdate=dateadd(day,1,@bdate) end RETURN @workdays; END GO ———————————————— 版权声明:本文为CSDN博主「仅此而已丶」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。 原文链接:https://blog.csdn.net/qq_32343577/article/details/89305844