我需要帮助才能知道两个特定日期之间有多少星期五。我找到并阅读了有关的帖子; Work days between two dates - 但我无法破解如何计算两个日期之间的特定日期。我需要一个更可靠的解决方案而不是将其除以7。
谢谢!
答案 0 :(得分:0)
declare @startDate date;
declare @endDate date;
select @startDate = '2017-02-01';
select @endDate = '2017-02-10';
with dateBetween as
(
select dt = dateadd(dd, 1, @startDate)
where dateadd(dd, 1, @startDate) < @endDate
union all
select dateadd(dd, 1, dt)
from dateBetween
where dateadd(dd,1, dt) < @endDate
)
select DATENAME(dw,dt) As [Dayname],dt as [Date]
from dateBetween where DATENAME(dw,dt) ='Friday'
&#13;