Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Number of Mondays in a month
Message
From
20/10/2016 12:11:57
 
 
To
19/10/2016 20:31:42
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01642129
Message ID:
01642152
Views:
64
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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform