Number of working days between two dates(两个日期之间的工作日数)
问题描述
我想要日期之间的工作日数.例如,如果我们有 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;
这篇关于两个日期之间的工作日数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:两个日期之间的工作日数


- 更改自动增量起始编号? 2021-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01
- SQL 临时表问题 2022-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01