我在这里引用这篇文章。 vbscript asp - Find every Thursday in a given month
如果我想找到全年的星期二,我该怎么办呢?比方说2016?
我根据上面提到的帖子中的代码尝试了如下,但它只会返回8月而不是全年
base_date = cdate("21 aug 2016")
'get 1st thursday;
thurs = dateserial(year(base_date), month(base_date), 1)
'response.write(weekday(thurs))
if (weekday(thurs) <> 1) then thurs = 3 - weekday(thurs) + thurs
'response.write(thurs)
'loop subsequent;
do until month(thurs) <> month(base_date)
response.write(thurs)
response.write("<br />")
thurs = dateadd("d", 7, thurs)
loop
答案 0 :(得分:1)
这是一个过于复杂的例子,当For
循环同样具有固定的起点和终点时。
Dim day
Dim startdate : startdate = CDate("22 mar 2015")
Dim enddate : enddate = CDate("22 mar 2016")
For day = startdate To enddate
If WeekDay(day) = vbTuesday Then Response.Write day & " = Tuesday"
Next
输出:
24/03/2015 = Tuesday
31/03/2015 = Tuesday
07/04/2015 = Tuesday
14/04/2015 = Tuesday
21/04/2015 = Tuesday
28/04/2015 = Tuesday
05/05/2015 = Tuesday
12/05/2015 = Tuesday
19/05/2015 = Tuesday
26/05/2015 = Tuesday
02/06/2015 = Tuesday
09/06/2015 = Tuesday
16/06/2015 = Tuesday
23/06/2015 = Tuesday
30/06/2015 = Tuesday
07/07/2015 = Tuesday
14/07/2015 = Tuesday
21/07/2015 = Tuesday
28/07/2015 = Tuesday
04/08/2015 = Tuesday
11/08/2015 = Tuesday
18/08/2015 = Tuesday
25/08/2015 = Tuesday
01/09/2015 = Tuesday
08/09/2015 = Tuesday
15/09/2015 = Tuesday
22/09/2015 = Tuesday
29/09/2015 = Tuesday
06/10/2015 = Tuesday
13/10/2015 = Tuesday
20/10/2015 = Tuesday
27/10/2015 = Tuesday
03/11/2015 = Tuesday
10/11/2015 = Tuesday
17/11/2015 = Tuesday
24/11/2015 = Tuesday
01/12/2015 = Tuesday
08/12/2015 = Tuesday
15/12/2015 = Tuesday
22/12/2015 = Tuesday
29/12/2015 = Tuesday
05/01/2016 = Tuesday
12/01/2016 = Tuesday
19/01/2016 = Tuesday
26/01/2016 = Tuesday
02/02/2016 = Tuesday
09/02/2016 = Tuesday
16/02/2016 = Tuesday
23/02/2016 = Tuesday
01/03/2016 = Tuesday
08/03/2016 = Tuesday
15/03/2016 = Tuesday
22/03/2016 = Tuesday
您可以在此处使用任何有效的Date Time Constants代替vbTuesday
。