;------------------------------------------------------------------------------------------------------------------------------------------ ; Note: This UDF "udfWeekOfYear" is obsolete. ; Replacement is: udfWeekOfYearISO ;------------------------------------------------------------------------------------------------------------------------------------------ #DefineFunction udfWeekOfYear (strYmdHms) intJulianNow = TimeJulianDay (strYmdHms) intJulianJan4 = TimeJulianDay (ItemExtract (1, strYmdHms, ":") : ":1:4") intJulianDowJan4 = (intJulianJan4 + 5) mod 7 ; Range=0..6 = Sunday..Saturday intJulianMonday = 1 + intJulianJan4 - intJulianDowJan4 - (7 * !intJulianDowJan4) intWeek = (intJulianNow - intJulianMonday) / 7 intWeek = intWeek + (intJulianNow >= intJulianMonday) Return intWeek ;.......................................................................................................................................... ; The return value is an integer number in the range 0..53. ; ; ISO8601 defines Monday as the first day of any week. ; Week W01 of any year is the first week that contains January 4. ; In some years January 1, 2 and 3 could fall into week W52 or W53 of the previous year. ; The last few days of December could fall into week W01 of the following year. ; ; Detlev Dalitz.20010325.20090726. ;.......................................................................................................................................... #EndFunction ;------------------------------------------------------------------------------------------------------------------------------------------ ; Test. ; Week of year. strYmdHms01 = "1975:12:28:00:00:00" ; Sunday intWoy01 = udfWeekOfYear (strYmdHms01) ; 52 strYmdHms02 = "1975:12:31:00:00:00" ; Wednesday intWoy02 = udfWeekOfYear (strYmdHms02) ; 53 ; 1975 Dezember ; Mo Di Mi Do Fr Sa So ; W49 1 2 3 4 5 6 7 ; W50 8 9 10 11 12 13 14 ; W51 15 16 17 18 19 20 21 ; W52 22 23 24 25 26 27 28 ; W53 29 30 31 strYmdHms03 = "1976:01:01:00:00:00" ; Thursday intWoy03 = udfWeekOfYear (strYmdHms03) ; 1 strYmdHms04 = "1976:01:02:00:00:00" ; Friday intWoy04 = udfWeekOfYear (strYmdHms04) ; 1 ; 1976 Januar ; Mo Di Mi Do Fr Sa So ; W01 1 2 3 4 ; W02 5 6 7 8 9 10 11 ; W03 12 13 14 15 16 17 18 ; W04 19 20 21 22 23 24 25 ; W05 26 27 28 29 30 31 strYmdHms05 = "1977:01:02:00:00:00" ; Sunday intWoy05 = udfWeekOfYear (strYmdHms05) ; 0 strYmdHms06 = "1977:01:03:00:00:00" ; Monday intWoy06 = udfWeekOfYear (strYmdHms06) ; 1 ; 1977 Januar ; Mo Di Mi Do Fr Sa So ; W00 1 2 ; W01 3 4 5 6 7 8 9 ; W02 10 11 12 13 14 15 16 ; W03 17 18 19 20 21 22 23 ; W04 24 25 26 27 28 29 30 ; W05 31 strYmdHms07 = "2002:01:01:00:00:00" ; Tuesday intWoy07 = udfWeekOfYear (strYmdHms07) ; 1 strYmdHms08 = "2002:01:07:00:00:00" ; Monday intWoy08 = udfWeekOfYear (strYmdHms08) ; 2 ; 2002 Januar ; Mo Di Mi Do Fr Sa So ; W01 1 2 3 4 5 6 ; W02 7 8 9 10 11 12 13 ; W03 14 15 16 17 18 19 20 ; W04 21 22 23 24 25 26 27 ; W05 28 29 30 31 strYmdHms09 = "2009:07:26:00:00:00" ; Sunday intWoy09 = udfWeekOfYear (strYmdHms09) ; 30 strYmdHms10 = "2009:07:27:00:00:00" ; Monday intWoy10 = udfWeekOfYear (strYmdHms10) ; 31 ; 2009 Juli ; Mo Di Mi Do Fr Sa So ; W27 1 2 3 4 5 ; W28 6 7 8 9 10 11 12 ; W29 13 14 15 16 17 18 19 ; W30 20 21 22 23 24 25 26 ; W31 27 28 29 30 31 Exit