Finding Tuesday for the whole year in ASP Classic

2019-09-13 11:38发布

问题:

im refereing to this post here. vbscript asp - Find every Thursday in a given month

How im supposed to do it if i wanna find the tuesday for the whole year? let say 2016?

I did try as below based on the code from the post i mentioned above, but it will return me only for August, instead of whole year

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

回答1:

That is an overly complicated example, when a For loop works just as well with a fixed start and end point.

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

Output:

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

You can use any of the valid Date Time Constants here instead of vbTuesday.