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;
这篇关于两个日期之间的工作日数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:两个日期之间的工作日数


基础教程推荐
- 无法在 ubuntu 中启动 mysql 服务器 2021-01-01
- Sql Server 字符串到日期的转换 2021-01-01
- 使用pyodbc“不安全"的Python多处理和数据库访问? 2022-01-01
- SQL Server 中单行 MERGE/upsert 的语法 2021-01-01
- SQL Server 2016更改对象所有者 2022-01-01
- 在 VB.NET 中更新 SQL Server DateTime 列 2021-01-01
- SQL Server:只有 GROUP BY 中的最后一个条目 2021-01-01
- 将数据从 MS SQL 迁移到 PostgreSQL? 2022-01-01
- 如何在 SQL Server 的嵌套过程中处理事务? 2021-01-01
- ERROR 2006 (HY000): MySQL 服务器已经消失 2021-01-01