;------------------------------------------------------------------------------------------------------------------------------------------ #DefineFunction udfGetWeekDay (strYmdHms, intDirection) Switch intDirection Case @FWDSCAN intJulianNow = TimeJulianDay (strYmdHms) While @TRUE intJulianNow = intJulianNow + 1 intJulianDow = (intJulianNow + 5) mod 7 If (6 != intJulianDow) Then If (0 != intJulianDow) Then Break ; If not a weekend day then break. EndWhile Return TimeJulToYmd (intJulianNow) Case @BACKSCAN intJulianNow = TimeJulianDay (strYmdHms) While @TRUE intJulianNow = intJulianNow - 1 intJulianDow = (intJulianNow + 5) mod 7 If (6 != intJulianDow) Then If (0 != intJulianDow) Then Break ; If not a weekend day then break. EndWhile Return TimeJulToYmd (intJulianNow) EndSwitch Return strYmdHms ;.......................................................................................................................................... ; This user defined function "udfGetWeekDay" returns a DateTime string containing ; either the previous week or the next week day (which is not a weekend day) starting at ; the given DateTime into direction given by the second parameter (@BACKSCAN resp. @FWDSCAN). ; The function returns the date of the following weekday (Monday through Friday). ; The algorithm skips over the weekend if necessary. No check for holidays which reside on weekdays. ; Weekend days are Saturday and Sunday. ; ; Detlev Dalitz.20090726. ;.......................................................................................................................................... #EndFunction ;------------------------------------------------------------------------------------------------------------------------------------------ ;------------------------------------------------------------------------------------------------------------------------------------------ #DefineFunction udfGetWeekDayPrev (strYmdHms) intJulianNow = TimeJulianDay (strYmdHms) While @TRUE intJulianNow = intJulianNow - 1 intJulianDow = (intJulianNow + 5) mod 7 If (6 != intJulianDow) Then If (0 != intJulianDow) Then Break ; If not a weekend day then break. EndWhile Return TimeJulToYmd (intJulianNow) ;.......................................................................................................................................... ; This user defined function "udfGetWeekDayPrev" returns a DateTime string containing the previous week day (which is not a weekend day). ; The function returns the date of the previous weekday (Monday through Friday). ; The algorithm skips over the Weekend if necessary. No check for holidays which reside on weekdays. ; Weekend days are Saturday and Sunday. ; ; Detlev Dalitz.20020723.20090726. ;.......................................................................................................................................... #EndFunction ;------------------------------------------------------------------------------------------------------------------------------------------ ;------------------------------------------------------------------------------------------------------------------------------------------ #DefineFunction udfGetWeekDayNext (strYmdHms) intJulianNow = TimeJulianDay (strYmdHms) While @TRUE intJulianNow = intJulianNow + 1 intJulianDow = (intJulianNow + 5) mod 7 If (6 != intJulianDow) Then If (0 != intJulianDow) Then Break ; If not a weekend day then break. EndWhile Return TimeJulToYmd (intJulianNow) ;.......................................................................................................................................... ; This user defined function "udfGetWeekDayNext" returns a DateTime string containing the next week day (which is not a weekend day). ; The function returns the date of the following weekday (Monday through Friday). ; The algorithm skips over the weekend if necessary. No check for holidays which reside on weekdays. ; Weekend days are Saturday and Sunday. ; ; Detlev Dalitz.20020723.20090726. ;.......................................................................................................................................... #EndFunction ;------------------------------------------------------------------------------------------------------------------------------------------ ; Test. ; udfGetWeekDayPrev (strYmdHms) strYmdHms11 = udfGetWeekDayPrev ("2002:10:25:00:00:00") ; "2002:10:24:00:00:00" strYmdHms12 = udfGetWeekDayPrev ("2002:10:26:00:00:00") ; "2002:10:25:00:00:00" strYmdHms13 = udfGetWeekDayPrev ("2002:10:27:00:00:00") ; "2002:10:25:00:00:00" strYmdHms14 = udfGetWeekDayPrev ("2002:10:28:00:00:00") ; "2002:10:25:00:00:00" strYmdHms15 = udfGetWeekDayPrev (TimeYmdHms ()) ; udfGetWeekDayNext (strYmdHms) strYmdHms21 = udfGetWeekDayNext ("2002:10:25:00:00:00") ; "2002:10:28:00:00:00" strYmdHms22 = udfGetWeekDayNext ("2002:10:26:00:00:00") ; "2002:10:28:00:00:00" strYmdHms23 = udfGetWeekDayNext ("2002:10:27:00:00:00") ; "2002:10:28:00:00:00" strYmdHms24 = udfGetWeekDayNext ("2002:10:28:00:00:00") ; "2002:10:29:00:00:00" strYmdHms25 = udfGetWeekDayNext (TimeYmdHms ()) ; 2002 Oktober ; Mo Di Mi Do Fr Sa So ; W40 1 2 3 4 5 6 ; W41 7 8 9 10 11 12 13 ; W42 14 15 16 17 18 19 20 ; W43 21 22 23 24 25 26 27 ; W44 28 29 30 31 ; udfGetWeekDay (strYmdHms, intDirection) strYmdHms31 = udfGetWeekDay ("2002:10:25:00:00:00", @BACKSCAN) ; "2002:10:24:00:00:00" strYmdHms32 = udfGetWeekDay ("2002:10:26:00:00:00", @BACKSCAN) ; "2002:10:25:00:00:00" strYmdHms33 = udfGetWeekDay ("2002:10:27:00:00:00", @BACKSCAN) ; "2002:10:25:00:00:00" strYmdHms34 = udfGetWeekDay ("2002:10:28:00:00:00", @BACKSCAN) ; "2002:10:25:00:00:00" strYmdHms35 = udfGetWeekDay (TimeYmdHms (), @BACKSCAN) strYmdHms41 = udfGetWeekDay ("2002:10:25:00:00:00", @FWDSCAN) ; "2002:10:28:00:00:00" strYmdHms42 = udfGetWeekDay ("2002:10:26:00:00:00", @FWDSCAN) ; "2002:10:28:00:00:00" strYmdHms43 = udfGetWeekDay ("2002:10:27:00:00:00", @FWDSCAN) ; "2002:10:28:00:00:00" strYmdHms44 = udfGetWeekDay ("2002:10:28:00:00:00", @FWDSCAN) ; "2002:10:29:00:00:00" strYmdHms45 = udfGetWeekDay (TimeYmdHms (), @FWDSCAN) Exit