المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : find week num of first week in year [modified]



C# Programming
01-08-2010, 01:51 PM
Hi,
I want to know the first week num of Jan 2010 if first day of week is Monday. All day before monday should be considered under last week of previous year, i.e. As first monday comes on 4th Jan 2010, i.e. I am expecting Jan 1,2 & 3 under week 53 of last year.

I am using this code
System.Globalization.CultureInfo currentCulture = System.Globalization.CultureInfo.CurrentCulture;
System.Globalization.Calendar calendar = currentCulture.Calendar;
DateTime firstOfYear = new DateTime(DateTime.Now.Year, 1, 1);

int weekNo = calendar.GetWeekOfYear(firstOfYear, System.Globalization.CalendarWeekRule.FirstFullWeek, DayOfWeek.Monday);

The week num is coming 52 instead of 53. What is going wrong? Is there any other way to do it?

Thanks.

modified on Thursday, January 7, 2010 10:19 AM