;------------------------------------------------------------------------------------------------------------------------------------------ #DefineFunction udfGetCountDowInPeriod (strYmdHmsStart, strYmdHmsStop, intDayOfWeek) intDayOfWeek = intDayOfWeek mod 7 ; For sure. intDayOfWeekStart = (5 + TimeJulianDay (strYmdHmsStart)) mod 7 ; Day of week of the starting date. Return (TimeDiffDays (strYmdHmsStop, strYmdHmsStart) + intDayOfWeekStart - intDayOfWeek + 7 * (intDayOfWeek >= intDayOfWeekStart)) / 7 ;.......................................................................................................................................... ; This UDF "udfGetCountDowInPeriod" returns the number of occurrences of the given day of week within the given date period. ; ; Parameters: ; strYmdHmsStart ... Starting date (as WinBatch DateTime string DT-10 or DT-19). ; strYmdHmsStop .... Stopping date (as WinBatch DateTime string DT-10 or DT-19). ; intDayOfWeek ..... Day of the week (as integer number in the Julian date system). ; 0 = Sunday, 1 = Monday, 2 = Tuesday, 3 = Wednesday, 4 = Thursday, 5 = Friday, 6 = Saturday. ; ; Note: Starting date must be less than stopping date. ; ; (c)Detlev Dalitz.20120102. ;.......................................................................................................................................... #EndFunction ;------------------------------------------------------------------------------------------------------------------------------------------ ; Test1. ; Prepare the period of time. intDaysDiff = 16 ; Next 16 days. strYmdHmsStart = TimeYmdHms () ; Today. strYmdHmsStop = TimeAdd (strYmdHmsStart, "0:0:" : intDaysDiff : ":0:0:0") ; Starting date plus some days into the future. ; Set the day of week to search for. intDayOfWeek = 3 ; Julian days: 0=Sunday, 1=Monday, 2=Tuesday, 3=Wednesday, 4=Thursday, 5=Friday, 6=Saturday. ; Result. The number of the given day of week between starting date and stopping date. intDowCount1 = udfGetCountDowInPeriod (strYmdHmsStart, strYmdHmsStop, intDayOfWeek) ; Test2. ; Prepare the period of time. strYmdHmsStart = "2009:02:01" strYmdHmsStop = TimeYmdHms () strDateTimeDiff = TimeDiff (strYmdHmsStop, strYmdHmsStart) ; Set the day of week to search for. intDayOfWeek = 0 ; Julian days: 0=Sunday, 1=Monday, 2=Tuesday, 3=Wednesday, 4=Thursday, 5=Friday, 6=Saturday. ; Result. The number of sundays since starting date until today. intDowCount2 = udfGetCountDowInPeriod (strYmdHmsStart, strYmdHmsStop, intDayOfWeek) :CANCEL Exit