Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Number of Mondays in a month
Message
From
20/10/2016 12:50:46
 
 
To
20/10/2016 12:11:57
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01642129
Message ID:
01642161
Views:
46
>The application has to determine how many occurrences of a given day of the week occurred in a given calendar month.
>
>This one does the inverse of what you are asking for - but it might give you some ideas:
>
>
>**********************************************************************
>* 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
This gave me an idea
My first attempt looks something like this
 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
 ENDDO
If 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
 ENDDO
That reduces the loop by 12 iterations or more
I think that's a good balance of simplicity and performance.
Anyone who does not go overboard- deserves to.
Malcolm Forbes, Sr.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform