Dear Gents,
For example, if Sounday is first day.
I need to get 4 monthday from week of month. (1,2,3,4)
for week two in this month, I need to get (5,6,7,8,9,10,11)
........
So if I know the week of this month. How can I get 1st day of this week or last of this week?
Thanks.
The week of month codes are following.
For example, if Sounday is first day.
I need to get 4 monthday from week of month. (1,2,3,4)
for week two in this month, I need to get (5,6,7,8,9,10,11)
........
So if I know the week of this month. How can I get 1st day of this week or last of this week?
Thanks.
The week of month codes are following.
Code:
Function WeekOfMonth(selDate As Date)
Dim DayOfFirst As Integer
Dim StartOfWeek2 As Integer
Dim weekNum As Integer
DayOfFirst = Weekday(DateSerial(Year(selDate), Month(selDate), 1), vbSunday)
StartOfWeek2 = (7 - DayOfFirst) + 2
Select Case selDate
Case DateSerial(Year(selDate), Month(selDate), 1) _
To DateSerial(Year(selDate), Month(selDate), StartOfWeek2 - 1)
weekNum = 1
Case DateSerial(Year(selDate), Month(selDate), StartOfWeek2) _
To DateSerial(Year(selDate), Month(selDate), StartOfWeek2 + 6)
weekNum = 2
Case DateSerial(Year(selDate), Month(selDate), StartOfWeek2 + 7) _
To DateSerial(Year(selDate), Month(selDate), StartOfWeek2 + 13)
weekNum = 3
Case DateSerial(Year(selDate), Month(selDate), StartOfWeek2 + 14) _
To DateSerial(Year(selDate), Month(selDate), StartOfWeek2 + 20)
weekNum = 4
Case DateSerial(Year(selDate), Month(selDate), StartOfWeek2 + 21) _
To DateSerial(Year(selDate), Month(selDate), StartOfWeek2 + 27)
weekNum = 5
Case DateSerial(Year(selDate), Month(selDate), StartOfWeek2 + 28) _
To DateSerial(Year(selDate), Month(selDate) + 1, 1)
weekNum = 6
End Select
WeekOfMonth = weekNum
End Function