SQL Server 2008 - 两个日期列之间的工作日数

时间:2015-12-15 13:26:57

标签: sql-server-2008

任何有关语法的帮助都将不胜感激。

Datediff(day,dateOne, dateTwo) as TimeServed

除周六和周日外,我如何获得这些日期之间的天数? 我没有能力创建功能。

1 个答案:

答案 0 :(得分:0)

请查看以下代码,这可能会有所帮助:

declare @firstdate Date
declare @seconddate Date

set @firstDate = convert(date, '2019-11-01')
set @seconddate = convert(date, '2019-11-30')


select ((datediff(dd, @firstDate, @secondDate)+1) - 
    ( DateDiff(wk, @firstDate, @secondDate) * 2) - 
      case when datepart(dw, @FirstDate) = 1 then 1 else 0 end -
      case when datepart(dw, @secondDate) = 7 then 1 else 0 end)