>********************************************************************** >* Program....: nthSomeDayOfMonth >* Compiler...: Visual FoxPro 06.00.8492.00 for Windows >* Abstract...: Returns the date of a specific type of day; e.g., the >* ...........: second Tuesday in November of the year 2001 >* ...........: nthSomedayOfMonth( 4, 3, 7, 2000 ) returns the date of >* ...........: the 3rd Wednesday in July of the year 2000 >* Parameters.: tnDayNum: Day number 1=Sunday 7=Saturday >* ...........: tnWhich : Which one to find; 1st, 2nd, etc. >* ...........: If tnwhich > the number of this kind of day >* ...........: in the month, the last one is returned >* ...........: tnMonth : Month Number in which to find the day >* ...........: tnYear : Year in which to find the day >********************************************************************** >FUNCTION nthSomedayOfMonth( tnDayNum, tnWhich, tnMonth, tnYear ) >LOCAL ldDate, lnCnt > >*** Start at the first day of the specified month >ldDate = DATE( tnYear, tnMonth, 01 ) > >*** Find the first one of the specified day of the week >DO WHILE DOW( ldDate ) # tnDayNum > ldDate = ldDate + 1 >ENDDO > >*** Find the specified one of these...e.g, 2nd, 3rd, or last >IF tnWhich > 1 > lnCnt = 1 > DO WHILE lnCnt < tnWhich > lnCnt = lnCnt + 1 > *** Move forward one week to get the next one of these in the month > ldDate = ldDate + 7 > *** Are we are still in the correct month? > IF MONTH( ldDate ) # tnMonth > *** If not, jump back to the last one of these we found and exit > ldDate = ldDate - 7 > EXIT > ENDIF > ENDDO >ENDIF > >RETURN ldDate >Thank you Marcia
DO WHILE ld_firstdrop < ld_enddate *-- If the item is schedule for this day, create a record in the billing table IF RIGHT(STR(DOW(ld_firstdrop)),1) = a_acrech->dayofweek ** process the day ENDIF ld_firstdrop = ld_firstdrop + 1 ENDDOIf I change it as follows:
DO WHILE ld_firstdrop < ld_enddate *-- If the item is schedule for this day, create a record in the billing table IF RIGHT(STR(DOW(ld_firstdrop)),1) = a_acrech->DAYOFWEEK ** process the day ld_firstdrop = ld_firstdrop + 7 ELSE ld_firstdrop = ld_firstdrop + 1 ENDIF ENDDOThat reduces the loop by 12 iterations or more