Vince wrote:
Given a week Number, how do I calculate the date that for the Monday
of that week?
You could copy this code into a module and play around with it. Change
intWeekNum in GetTheMonday for the number of weeks to add to test. You
can see this year's (2008) first Monday week is before the first of the
year so make adjustments as required.
Run GetTheMonday to cycle thru 2006-2008. Check results in Immediate
window.
Private Sub GetTheMonday
Dim datMonday As Date
Dim intFor as Integer
Dim intWeekNum As Integer
intWeekNum = 1 'week number to calc date from
'show in debug window the first monday for years 2006-2008
For intFor = 2006 to 2008
'get date of first monday in year 2008
Debug.Print MondayWeek(intFor,intWeekNum)
Next
endif
Public Function MondayWeek(intYear As integer, _
intWeek As Integer) As Date
Dim dat As Date
Dim intD As Integer
'calc first day of year of datFld
dat = DateSerial(intYear, 1, 1)
intD = WeekDay(dat)
Select Case intD
Case 1
dat = dat + 1
Case Else
'subtract 2 to get first Monday
dat = dat - (intD - 2)
End Select
'if datYear is
'2006 1/2/2006 is first monday
'2007 1/1/2007 is first monday
'2008 12/31/2007 is first monday
'add number of weeks minus 1 to first monday
MondayWeek = DateAdd("ww", intWeek - 1, dat)
End Function
Gronlandic Edit
http://www.youtube.com/watch?v=HBfgQvM7wtE