1
以下是我計算當月工作天數的代碼。計算月份剩餘的總工作日數
DECLARE @my int
DECLARE @myDeduct int
DECLARE @day INT
DECLARE @mydate DATETIME
SET @mydate = getDate()
SET @myDeduct = 0
SET DateFirst 1 -- Set it monday=1 (value)
--Saturday and Sunday on the first and last day of a month will Deduct 1
IF (DATEPART(weekday,(DATEADD(dd,-(DAY(@mydate)-1),@mydate))) > 5)
SET @myDeduct = @myDeduct + 1
IF (DATEPART(weekday,(DATEADD(dd,-(DAY(DATEADD(mm,1,@mydate))),
DATEADD(mm,1,@mydate)))) > 5)
SET @myDeduct = @myDeduct + 1
SET @my = day(DATEADD(dd,-(DAY(DATEADD(mm,1,@mydate))),DATEADD(mm,1,@mydate)))
select (((@my/7) * 5 + (@my%7)) - @myDeduct) as Working_Day_per_month
我現在該如何計算當月有多少工作日? 不擔心公共假期。
謝謝,請參閱我的答案,關於如何將它用於CTE – Etienne