how can i get the date of the month for each monda

# Thread: how can i get the date of the month for each monda

1. newtoo Guest

## how can i get the date of the month for each monda

i want to be able to just print the date for each monday in a<BR>month. is this possible and how would i go about doing it?

2. KPW Guest

## RE: how can i get the date of the month for each m

For i = 1 to 31<BR>&nbsp;&nbsp;sTempDate = (Month(Date) & "/" & i & "/" & Year(Date))<BR>&nbsp;&nbsp;If IsDate(sTempDate) then<BR>&nbsp;&nbsp;&nbsp;&nbsp;If Weekday(CDate(sTempDate)) = 2 then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Respon se.Write sTempDate<BR>&nbsp;&nbsp;&nbsp;&nbsp;End If<BR>&nbsp;&nbsp;End If<BR>Next &#039i

3. schnookums Guest

## RE: how can i get the date of the month for each m

off the top of my head (meaning untested):<BR><BR>intMonth = 5 &#039 This is the month of May<BR>intDay = 1 &#039Start at day 1<BR>intYear = year(now) &#039 This year<BR><BR><BR>do<BR> dtTestDate = intMonth & "/" & intDay & "/" & intYear<BR>loop until Weekday(dtTestDate) = vbMonday<BR><BR>response.write dtTestDate & "<BR>"<BR><BR>flgBad = False<BR>do<BR> dtTestDate = dateadd("d", 7, dtTestDate)<BR> if isDate(dtTestDate) then<BR> response.write dtTestDate & "<BR>"<BR> else<BR> flgBad = True<BR> end if<BR>loop while flgBad = False

4. newtoo Guest

## RE: how can i get the date of the month for each m

thanks, is there a way so i don&#039t have to go change it every month depending on how many days in the month there are???

5. schnookums Guest

## RE: how can i get the date of the month for each m

My example handles that problem

6. schnookums Guest

## RE: how can i get the date of the month for each m

Here... this one I did test (minor changes)<BR><BR>&#060;%<BR>intMonth = 8 &#039 This is the month of May<BR>intDay = 1 &#039Start at day 1<BR>intYear = year(now) &#039 This year<BR><BR><BR>dtTestDate = intMonth & "/" & intDay & "/" & intYear<BR>while Weekday(dtTestDate) &#060;&#062; vbMonday<BR> dtTestDate = dateAdd("d", 1, dtTestDate)<BR>wend<BR><BR>response.write dtTestDate & "&#060;<BR>&#062;"<BR><BR>flgBad = False<BR>do<BR>dtTestDate = dateadd("d", 7, dtTestDate)<BR>if isDate(dtTestDate) and month(dtTestDate) = intMonth then<BR>response.write dtTestDate & "&#060;<BR>&#062;"<BR>else<BR>flgBad = True<BR>end if<BR>loop while flgBad = False<BR><BR>%&#062;

7. KPW Guest

## Doesn't it do that already?

Sure, I use a loop counter from 1 to 31. But that&#039s because 31 is the maximum number of days that can be in a month. In each pass through the loop, I then use the IsDate function to test if the date in sTempDate is an actual date. Therefore, you wouldn&#039t get 2/31/00 as a valid date.<BR><BR>Only after passing that check do I continue to check whether the date is a Monday. (I liked schnookums use of vbMonday, BTW.)<BR><BR>I guess the only other modification I would make is to exit the for...next loop once you hit an invalid date. For example, once you hit 2/29/01 there is no need to test the validity of 2/30/01.<BR><BR>For i = 1 to 31<BR> sTempDate = (Month(Date) & "/" & i & "/" & Year(Date))<BR> If IsDate(sTempDate) then<BR> If Weekday(CDate(sTempDate)) = 2 then<BR> Response.Write sTempDate<BR> End If<BR> Else<BR> Exit For<BR> End If<BR>Next &#039i<BR><BR>My example, of course, can be modified so that you can specify the month and year, instead of just assuming the current month and year.

8. newtoo Guest