两个日期之间的工作日数
我想要日期之间的工作日数.例如,如果我们有 01-01-2012 和 20-01-2012,我想使用 T-SQL 获取这两个日期之间的工作日数.
I want number of working days in between to dates. For example if we have 01-01-2012 and 20-01-2012, i want to get the number of working days in between that two dates using T-SQL.
推荐答案
由于 SQL Server 不知道贵公司认为工作日是多少,因此这个问题的最佳答案可能是使用 日历表.一旦你有一个包含过去和未来日期的表,并且像 IsWorkDay
这样的列正确更新,查询就很简单:
Since SQL Server has no idea what your company considers working days, the best answer to this problem is likely going to be to use a calendar table. Once you have a table with past and future dates, with a column like IsWorkDay
correctly updated, the query is simple:
SELECT [Date] FROM dbo.Calendar
WHERE [Date] >= @start
AND [Date] <= @end
AND IsWorkDay = 1;
相关文章