Return week as week 1 when December 31 is selecrtet.

           Me.txtWeekNum.Text = DatePart(DateInterval.WeekOfYear, CDate(txtWeekEnding.Text), Microsoft.VisualBasic.FirstDayOfWeek.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?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

52 weeks * 7 days = 364...leaving 1 day extra for week 53

If you want this to always be the first week of the next year, just look for 53 and make it = 1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
You can also add another parameter to DatePart which specifies what constitutes the first week of the year.  It defaults to Jan. 1, which is the way you have it, making Dec. 31 fall into week 53.

However, you can specify other settings also.
FirstWeekOfYear.System=First week of year specified in system settings
FirstWeekOfYear.Jan1=Week in which January 1 occurs (default)
FirstWeekOfYear.FirstFourDays=First week that has at least four days in the new year (complies with ISO standard 8601, section 3.17)

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.
 First full week in new year
try this

Me.txtWeekNum.Text = DatePart(DateInterval.WeekOfYear, Dateadd(DateInterval.Day, CDate(txtWeekEnding.Text), 7 - datepart(DateInterval.Weekday, Date(txtWeekEnding.Text), Microsoft.VisualBasic.FirstDayOfWeek.Monday)), Microsoft.VisualBasic.FirstDayOfWeek.Monday)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.