kejpa Posted December 16, 2004 Posted December 16, 2004 Hi, I've bumped into some strange behaviour when trying to set the localization of my app. I want it to have Monday as the first day of week and the first 4 day-week as week # 1. However, Jan 1 is always week 1 in VB ... Not in my calendar, next year for instance it's week 53 (of this year) Jan 31 1999 is interesting. With my settings it would be week 4, but VB reports it as week 6 (which it will be if Jan1 is in week1 and Sunday is the first day of the week) Doesn't the settings of FirstDayOfWeek and CalendarWeekRule have any affect?!? Puzzled! /Kejpa Quote
Diesel Posted December 16, 2004 Posted December 16, 2004 What is CalenderWeekRule and how are you creating 4 days weeks? Quote
kejpa Posted December 17, 2004 Author Posted December 17, 2004 What is CalenderWeekRule and how are you creating 4 days weeks? Hold your horses! No! *panic* No 4 days weeks!!! I'd be better off with 10 days weeks, might keep the deadline then ;) Alright, back on topic. The week number of any specific date depends on which day is defined as your FirstDayOfWeek, some countries have Sunday, some Monday (and there might be others too) Another thing that the week number depends on is which week of the year that is defined as 1. Again different countries have different standards (btw Standards are great, everyone should have his...) some countries say that the week that contains Jan 1 is week 1. Some others say the first whole week is week 1, yet others say that the first week of the year containing at least 4 days is week 1. In 2005 this will bring problems to which week a date such as Jan 30 is in. Where I live Jan 30 is in week 4. (Mon is FirstDayOfWeek, first week has at least 4 days) In some countries it's week 5 (Mon is FirstDayOfWeek, Jan 1 is in week 1) In some countries it's week 6 (Sun is FirstDayOfWeek, Jan 1 is in week 1) How are we supposed to communicate which week we will deliver if there's such a big difference in the numbering of weeks?!?! Now, back to my Q. Why isn't these settings affecting what week number is returned from DatePart(DateInterval.WeekOfYear, "2005-01-30") /Kejpa Quote
kejpa Posted December 17, 2004 Author Posted December 17, 2004 Found it! DatePart(DateInterval.WeekOfYear, dtTest) is using FirstWeekOfYear.Jan1 and FirstDayOfWeek.Sunday as default values regardless of your local settings. In order to have them localized (why is MS using Globalization for localizing an app :confused: ) you have to write DatePart(DateInterval.WeekOfYear, dtTest,FirstDayOfWeek.System,FirstWeekOfYear.System) That's rude. /Kejpa Quote
Administrators PlausiblyDamp Posted December 17, 2004 Administrators Posted December 17, 2004 Rather than using the legacy VB6 date handling functions why not just use the methods / properties of the date itself? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
kejpa Posted December 17, 2004 Author Posted December 17, 2004 Rather than using the legacy VB6 date handling functions why not just use the methods / properties of the date itself? I'd gladly do! How do I get the week number by using the properties of the date? /Kejpa Quote
Administrators PlausiblyDamp Posted December 17, 2004 Administrators Posted December 17, 2004 Not tested it but have a go at something like Dim d As Date = Date.Now Dim c As Globalization.Calendar c = Globalization.CultureInfo.CurrentCulture.Calendar c.GetWeekOfYear(d, Globalization.CalendarWeekRule.FirstDay, DayOfWeek.Friday) Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.