关于日期:vbscript asp – 查找给定月份的每个星期四

vbscript asp - Find every Thursday in a given month

我正在尝试使用 VBScript 查找给定月份内的所有星期四。

谁能帮忙?


这是一种方法;

1
2
3
4
5
6
7
8
9
10
11
base_date = cdate("21 aug 2011")

'get 1st thursday;
thurs = dateserial(year(base_date), month(base_date), 1)
if (weekday(thurs) <> 1) then thurs = 5 - weekday(thurs) + thurs

'loop subsequent;
do until month(thurs) <> month(base_date)
    msgbox thurs
    thurs = dateadd("d", 7, thurs)
loop


虽然接受的答案可以完成工作,但对于可以通过 WeekDay() 函数和 For 循环完成的事情来说过于复杂。

1
2
3
4
5
6
7
8
9
10
Dim day
Dim startdate: startdate = CDate("21 aug 2011")
Dim enddate
'Get first day of month.
startdate = DateSerial(Year(startdate), Month(startdate), 1)
'Get last day of month.
enddate = DateAdd("m", 1, startdate) - 1
For day = startdate To enddate
  If WeekDay(day) = vbThursday Then WScript.Echo day &" =" & WeekDayName(WeekDay(day))
Next

输出:

1
2
3
4
04/08/2011 = Thursday
11/08/2011 = Thursday
18/08/2011 = Thursday
25/08/2011 = Thursday

此处可以使用任何日期和时间常量来查找不同或多个工作日,只需稍加修改即可。