![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Given a week Number, how do I calculate the date that for the Monday of that week? |
#3
| |||
| |||
|
|
Given a week Number, how do I calculate the date that for the Monday of that week? |
#4
| |||
| |||
|
|
Vince wrote: Given a week Number, how do I calculate the date that for theMonday 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) firstMondayweek 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 firstmondayfor years 2006-2008 * * * * For intFor = 2006 to 2008 * * * * * 'get date of firstmondayin 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 firstMonday * * * * *dat = dat - (intD - 2) * * *End Select * * *'if datYear is * * * * *'2006 1/2/2006 is firstmonday * * * * *'2007 1/1/2007 is firstmonday * * * * *'2008 12/31/2007 is firstmonday * * *'add number of weeks minus 1 to firstmonday * * *MondayWeek = DateAdd("ww", intWeek - 1, dat) End Function Gronlandic Edithttp://www.youtube.com/watch?v=HBfgQvM7wtE |
#5
| |||
| |||
|
|
On Oct 9, 7:34 am, Salad <o... (AT) vinegar (DOT) com> wrote: Vince wrote: Given a week Number, how do I calculate the date that for theMonday 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) firstMondayweek 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 firstmondayfor years 2006-2008 For intFor = 2006 to 2008 'get date of firstmondayin 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 firstMonday dat = dat - (intD - 2) End Select 'if datYear is '2006 1/2/2006 is firstmonday '2007 1/1/2007 is firstmonday '2008 12/31/2007 is firstmonday 'add number of weeks minus 1 to firstmonday MondayWeek = DateAdd("ww", intWeek - 1, dat) End Function Gronlandic Edithttp://www.youtube.com/watch?v=HBfgQvM7wtE thanks !! the Function MondayWeek worked for me! |
![]() |
| Thread Tools | |
| Display Modes | |
| |