Calculating days to excluding weekends (Monday to Friday) in SQL Server
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: How can I calculate the number of work days between two dates from table (from the 1st row to the end) in SQL Server 2008? I tried something like this, but it does not work DECLARE @StartDate as DATETIME, @EndDate as DATETIME Select @StartDate = date2 from testtable ; select @EndDate = date1 from testtable ; SELECT (DATEDIFF(dd, @StartDate, @EndDate) + 1) -(DATEDIFF(wk, @StartDate, @EndDate) * 2) -(CASE WHEN DATENAME(dw, @StartDate) = 'Sunday' THEN 1 ELSE 0 END) -(CASE WHEN DATENAME(dw, @EndDate) = 'Saturday' THEN 1 ELSE 0 END) 回答1: I would