计算 TSQL 中两个日期之间星期二的数量
确定两个日期之间星期二的数量是 TSQL 编程中的常见挑战。 t-clausen.dk 概述了一种有效的方法:
计算每个工作日的实例:
<code class="tsql">declare @from datetime = '3/1/2013' declare @to datetime = '3/31/2013' select datediff(day, -7, @to)/7-datediff(day, -6, @from)/7 AS MON, datediff(day, -6, @to)/7-datediff(day, -5, @from)/7 AS TUE, datediff(day, -5, @to)/7-datediff(day, -4, @from)/7 AS WED, datediff(day, -4, @to)/7-datediff(day, -3, @from)/7 AS THU, datediff(day, -3, @to)/7-datediff(day, -2, @from)/7 AS FRI, datediff(day, -2, @to)/7-datediff(day, -1, @from)/7 AS SAT, datediff(day, -1, @to)/7-datediff(day, 0, @from)/7 AS SUN</code>
此查询返回一周内每一天的出现次数指定的日期范围。计算基于以下原则:
通过应用此方法,您可以轻松确定给定日期范围内星期二或一周中任何其他日期的数量。
以上是如何在 TSQL 中计算两个日期之间的星期二数?的详细内容。更多信息请关注PHP中文网其他相关文章!