US (Sunday -> Saturday): 52 weeks + one short 2 day week for &.How many weeks there are really depends on the starting day of your week. Are these extra days counted as separate weeks of their own? So for each year you have at least one an extra day. Each year has 52 full weeks + 1 or +2 (leap year) days extra. There can be more than 52 weeks in a year. This presumes that weeks start with Monday. Update The following method actually returns -12-31 which is correct in ISO 8601 (e.g. In the article there is also a simple function to get the correct ISO 8601 week number for the last week of the year. Net allow weeks to be split across years while the ISO standard does not. You can refer to this article in MSDN Blog for a better explanation: " ISO 8601 Week of Year format in Microsoft. Return (time, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday) Īs noted in this MSDN page there is a slight difference between ISO8601 week and. If (day >= DayOfWeek.Monday & day <= DayOfWeek.Wednesday) be the same week# as whatever Thursday, Friday or Saturday are,ĭayOfWeek day = (time) If its Monday, Tuesday or Wednesday, then it'll Public static int GetIso8601WeekOfYear(DateTime time) Week 1 is the 1st week of the year with a Thursday in it. In other words, my problem was that my methods were not following the ISO-8601 standard. The following method actually returns 1 when date is. Int weekNum = (dtPassed, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday) Solution 3: CultureInfo ciCurr = CultureInfo.CurrentCulture Solution 2: return new GregorianCalendar(GregorianCalendarTypes.Localized).GetWeekOfYear(date, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday) Return cal.GetWeekOfYear(date, dfi.CalendarWeekRule, dfi.FirstDayOfWeek) Here are some of the methods, that I have tried:įrom the MDSN Library: DateTimeFormatInfo dfi = DateTimeFormatInfo.CurrentInfo is Monday, therefore it should be Week 1, but every method I tried gives me 53. I have Googled a lot and found a lot of solutions, but none of them give me the correct week number for the.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |