我们在今天/周三和周四的第一个星期二开始的4周周期内修补服务器,并且我正在寻找一种方法来确定我们将根据当前的周数日期。
例如,第一周周期全部为三天,周二为第5周,因此结婚(第6周)和周四(第7周)=第1周,依此类推4周周期。
但是如果第一个星期二碰巧是第一个星期二,那么这个月就会有5套。因此,在这些日子的第5集中不会发生修补。
所以我希望输出周数或显示"不打补丁#34;
If week contains (Tuesday (maxdates 1st -7th), Wednesday (maxdates 2nd-8th), Thursday (maxdates 3rd-9th) = week 1
Then if week contains (Tuesday (maxdates 8th -14th), Wednesday (maxdates 9th-15th), Thursday (maxdates 10th-16th) = week 2
Then if week contains (Tuesday (maxdates 15th -21st), Wednesday (maxdates 16th-22nd), Thursday (maxdates 17th-23rd) = week 3
Then if week contains (Tuesday (maxdates 22nd -28th), Wednesday (maxdates 23rd-29th), Thursday (maxdates 24th-30th) = week 4
Else "no patching due to take place"
但如果这个月没有第4周的第29或第30个,那么我需要包括第1和第2个。
理想情况下,这可以让我将其纳入我的日常任务列表中,而不必担心在未进行修补的一周内意外出现的任务。每天从sql数据库中提取任务列表。
答案 0 :(得分:0)
declare @v datetime = getdate()
select
DATENAME(weekday,@v) weekday,
@v date,
case
when DATENAME(weekday,@v) in ('Wednesday','Thursday')
AND 1 + ((DATEPART(day,@v) / 7) * 7) > 1
AND (DATEPART(day,@v) - ((DATEPART(day,@v) / 7) * 7) between 0 and 2)
then (DATEPART(day,@v) / 7)
else 1 + DATEPART(day,@v) / 7
end week_no