Question

How can I set week number of "1/2/2011(Sun)" as 52 of 2010?

When I write as follows, it says week number is "1".

Dim dtTest As Integer = DatePart(DateInterval.WeekOfYear, CDate("2012/01/02"), _
                                 FirstDayOfWeek.Monday, FirstWeekOfYear.FirstFullWeek)

Why is it? I set FirstDayOfWeek as Monday, so week number of "1/2/2011(Sun)" Should be 52, right?

"1/2/2011(Sun)" is just an example.

I want general method to do:
1. First day of week is Monday.
2. First week of year is the first full week which stat with Monday.
3. The last week of year should contain dates before the first week of the next year(such as 1/1/2011(Sat), 1/2/2011(Sun))

thx.

Was it helpful?

Solution

In your sample code, you have the year 2012 instead of 2011. 1/2/2011 gets week 52 with FirstDayOfWeek.Monday and FirstWeekOfYear.FirstFullWeek

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top