Dates

1. Junior Member
Join Date
Dec 1969
Posts
6

## Dates

Ok what iam looking for is the ability to get the date of every monday in any given year<BR><BR>Anyone that can help it would be appreciated<BR><BR>Many Thanks<BR><BR>Jason

2. Senior Member
Join Date
Dec 1969
Posts
1,015

## RE: Dates

What would be your input and expected output?

3. Junior Member
Join Date
Dec 1969
Posts
6

## RE: Dates

The would be now required input from the user i want it to be able to take the current year and work out what the date of every monday in that year would be with the results i will list in a list box

4. Senior Member
Join Date
Dec 1969
Posts
5,955

## Just find the first Monday in the year...

...and then add 7 days to that date until you get into the next year. Do a quick Google to find an algorithm which gives you the day of the week for a given date. Actually, VBScript might have something built in that does that. So, all you need to do is have a For 1 to 7 loop and check whether the 1 Jan, 2 Jan, 3 Jan, ... is a Monday and then stop if it is. The rest then goes as above.<BR><BR>Oliver.

5. God
Senior Member
Join Date
Dec 1969
Posts
18,177

## I can help w/ finding the..

.. first Monday:<BR>[code language="VBScript"]<BR>Function GetXOccuranceOfWeekdayInMonth(ByVal TheMonth, ByVal TheYear, ByVal TheWeekday, ByVal TheOccurance)<BR><BR>Dim dtOut<BR>Dim dtLoop<BR>Dim iCnt, _<BR> iOccuranceCnt<BR> dtLoop = DateSerial(TheYear, TheMonth, 1)<BR> <BR> While IsDate(dtOut) = False And Month(dtLoop) = TheMonth<BR> If Weekday(dtLoop) = TheWeekday Then<BR> iOccuranceCnt = iOccuranceCnt + 1<BR> <BR> If iOccuranceCnt = TheOccurance Then<BR> dtOut = dtLoop<BR> End If<BR> End If<BR> <BR> dtLoop = DateAdd("d", 1, dtLoop)<BR> Wend<BR> <BR> GetXOccuranceOfWeekdayInMonth = dtOut<BR><BR>End Function<BR>[/code]<BR>I had this lying around from my calendar code. To use it, you just do:<BR>[code language="VBScript"]<BR>firstMondayDate = GetXOccuranceOfWeekdayInMonth(1, Year(Date()), vbMonday, 1)<BR>[/code]<BR>Then you can do that other stuff that OK mentioned.

6. Junior Member
Join Date
Dec 1969
Posts
6

## RE: I can help w/ finding the..

Thanks guys, i will have a go later

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•