I have a
startdate 2010-01-01 (I just assume its a first day of the week)
and an
enddate 2010-07-31 (I just assume its a first day of the week)
I want to have returned from a method all week numbers for every first day of the week for the
above timespan. I can not assume that the first day of week is always monday, because my user
could be from Sweden, USA or whereever. The algorythm should be compatible with ISO 8601.
The final result should look roughly like this:
2010-01-01 , 1
2010-01-08 , 2
2010-01-15 , 3
2010-01-22 , 4
...
2010-07-31 , ~28
Yes I know google is full of links about that topic but nobody is doing it right. They all
assume that monday is first day of a week. Maybe some of the c# gods on SO pass by :P
EDIT:
What do you say to this code:
public static int GetWeekNumber(DateTime dtPassed)
{
CultureInfo ciCurr = CultureInfo.CurrentCulture;
int weekNum = ciCurr.Calendar.GetWeekOfYear(dtPassed, CalendarWeekRule.FirstDay, DateTimeFormatInfo.CurrentInfo.FirstDayOfWeek);
return weekNum;
}
I found it partly on google and changed it a bit.