Calendar Weeks

Dealing with Calendar Weeks in WinDev
 
Overview: WinDev offers the command WeekNumber(Date) which returns the calendar week number. The returned integer is between 0 to 53 as WD-Help says. However, there’s no such thing as a calendar week number zero! What happened? What are the principles? What to do?
 
1 - Most - but not all ! - ways to define the week number say: the first week of a given year is that one which has at least 4 or more days in the new year. All days before week 1 are attributed to the last week of the old year.
 
2 - Be aware of the fact, that Europeans start their week with Monday while US-Americans start it with Sunday! So, for Americans, the calculation of the week number will differ from European week numbers? Yes and no. For ‘rescue’ there comes the ISO week number. http://www.proesite.com/timex/wkcalc.htm and ISO 8601 in general: http://www.dmoz.org/Science/Reference/Standards/Individual_Standards/ISO/ISO_8601/ Theoretically, because in ISO 8601 another problem surfaces: Every 28th year is a year with 54 work weeks by ISO 8601 standard! So, there’s plenty of problems waiting for the unaware programmer.
 
3 - There are different rules to calculate week numbers for fiscal years and even for certain institutions, organisations and companies. All of the differences will be seen around the week number 1. Be aware that there’s an Islamic year (a moon year), the Jewish year and the Chinese Year too. It only seems that the common consensus is that a week has 7 days. Well, it seems to me that PC Soft programmers let it up to the individual programmer to decide about the details .. OK, here we are!
 
My solution for calculating the correct week number from a certain date
Note: this is for Europe / Austria. Things may be different in your continent / country / special situation - you have to take care of that!
 
MyWeekDayNum = IntegerToDay(DateToInteger(MyDate))
CalendarWeekNum = WeekNumber(MyDate)
 
IF Middle(MyDate, 5, 4) = "1229" AND MyWeekDayNum = 1 THEN CalendarWeekNum = 1
IF Middle(MyDate, 5, 4) = "1230" AND (MyWeekDayNum = 1 OR MyWeekDayNum = 2) THEN CalendarWeekNum = 1
IF Middle(MyDate, 5, 4) = "1231" AND (MyWeekDayNum = 1 OR MyWeekDayNum = 2 OR MyWeekDayNum = 3) THEN CalendarWeekNum = 1
IF Middle(MyDate, 5, 4) = "0101" AND (MyWeekDayNum = 5 OR MyWeekDayNum = 6 OR MyWeekDayNum = 7) THEN CalendarWeekNum = IntegerToWeekNumber(DateToInteger(MyDate)-1)
IF Middle(MyDate, 5, 4) = "0102" AND (MyWeekDayNum = 6 OR MyWeekDayNum = 7) THEN CalendarWeekNum = IntegerToWeekNumber(DateToInteger(MyDate)-2)
IF Middle(MyDate, 5, 4) = "0103" AND MyWeekDayNum = 7 THEN CalendarWeekNum = IntegerToWeekNumber(DateToInteger(MyDate)-3)
 
 

 

BuiltWithNOF
[Home] [English] [WX Links] [Deutsch] [Impressum] [Downloads] [RADTranslate] [Upper] [NullValues] [TableOnStructure] [HFClassicHFSQL] [RAD11] [USBFind] [Color Contrast] [Dec. Separator] [Setup Problems] [Directories] [Help Authoring] [Access CHM] [Make GUID] [HOpen Files] [Reset Table] [Int. Gen. Number] [TAB-Control] [fDataDir.. commands] [Calendar Weeks] [Input & check EAN 8/13] [Test_for_Dups] [Feiertage] [MemStick as Dongle] [Get Date & Time] [German phone book]