0

I am using the code below to get the current week of the year:

DateTimeFormatInfo dfi = DateTimeFormatInfo.CurrentInfo;
Calendar cal = dfi.Calendar;
cal.GetWeekOfYear(DateTime.Now, dfi.CalendarWeekRule, dfi.FirstDayOfWeek);

Right now its 19-02-2016 and the week number is 7, but the code above returns display 8.

Can anyone tell me what is wrong with the code?

Steve
  • 9,335
  • 10
  • 49
  • 81
Sunil Dabhi
  • 99
  • 2
  • 13
  • Now is week `8`. There is nothing wrong with the code... Why do you think that now is week `7`? – Ian Feb 19 '16 at 06:31
  • I had a similar problem, and I found this which helped me; Sorry, can't remember the original source. https://blogs.msdn.microsoft.com/shawnste/2006/01/24/iso-8601-week-of-year-format-in-microsoft-net/ – jason.kaisersmith Feb 19 '16 at 06:41
  • @Ian According to some week number rules yes, according to others no. The OP does not specify which week number rules to use (the OP's system default, but which is that?), so we cannot say whether the OP's result is supposed to be `7` or `8`. –  Feb 19 '16 at 07:44
  • @hvd I see. I typically only work locally - wasn't aware of this... – Ian Feb 19 '16 at 07:47

0 Answers0