expertsexchangehunter
asked on
Return week as week 1 when December 31 is selecrtet.
Me.txtWeekNum.Text = DatePart(DateInterval.Week OfYear, CDate(txtWeekEnding.Text), Microsoft.VisualBasic.Firs tDayOfWeek .Monday)
Which works fine for all weeks except if December 31 is selected in the Calendar which case the week returned is 53. I would like the week to be 1 for the first week in January. How can this be done?
Which works fine for all weeks except if December 31 is selected in the Calendar which case the week returned is 53. I would like the week to be 1 for the first week in January. How can this be done?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
try this
Me.txtWeekNum.Text = DatePart(DateInterval.Week OfYear, Dateadd(DateInterval.Day, CDate(txtWeekEnding.Text), 7 - datepart(DateInterval.Week day, Date(txtWeekEnding.Text), Microsoft.VisualBasic.Firs tDayOfWeek .Monday)), Microsoft.VisualBasic.Firs tDayOfWeek .Monday)
Me.txtWeekNum.Text = DatePart(DateInterval.Week
However, you can specify other settings also.
FirstWeekOfYear.System=Fir
FirstWeekOfYear.Jan1=Week in which January 1 occurs (default)
FirstWeekOfYear.FirstFourD
For 2007, just because of the day of the week Jan 1 fell on, it happened that only Dec. 31 was in week 53. But, for 2008, there are more days in week 53 due to the first week being short because Jan 1 fell in the middle of the week.
If you let it default to week of Jan1 as the first week of the year, you should be able to just let week 53 roll over into the next year's week 1.
Hope this makes sense.
FirstWeekOfYear.FirstFullW
3
First full week in new year