两个日期之间的天数(工作日)

--不算第一天
 SELECT CASE WHEN COUNT(*) = 0 THEN 1
             ELSE COUNT(*)
        END
 FROM   master..spt_values
 WHERE  number BETWEEN 1
               AND     DATEDIFF(dd, '2016/8/20', '2016/9/7')
        AND type = 'P'
        AND DATEPART(dw, DATEADD(dd, number - 1, '2016/8/20')) NOT IN ( 1, 7 )
--实际天数
 SELECT   COUNT(*)  
 FROM   master..spt_values
 WHERE  number BETWEEN 1
               AND     DATEDIFF(dd, '2016/8/20', '2016/9/7')
        AND type = 'P'
        AND DATEPART(dw, DATEADD(dd, number - 1, '2016/8/20')) NOT IN ( 1, 7 )

你可能感兴趣的:(SQL)