Microsoft KB Archive/114354

From BetaArchive Wiki
Knowledge Base


Article ID: 114354

Article Last Modified on 10/15/2003



APPLIES TO

  • Microsoft Visual FoxPro 3.0 Standard Edition
  • Microsoft FoxPro 2.6a Professional Edition for Macintosh



This article was previously published under Q114354

SUMMARY

This article describes how to programmatically determine the number of weekdays between and including a start date and an end date.

MORE INFORMATION

Code Example

   *program to return the number of weekdays between two dates
   *beginning with d1 through d2
   PARAMETERS d1,d2
   IF (TYPE("d1")="D" AND TYPE("d2")="D")   && both variables present?
      wd=0   && variable to hold total number of weekdays
      FOR D=0 TO d2-d1
         IF BETWEEN(DOW(d1+D),2,6)   && 2=Mon 6=Fri
            wd=wd+1
         ENDIF
      ENDFOR
      RETURN wd
   ELSE
      RETURN 0
   ENDIF
                

Save the program as WEEKDAYS.PRG. To call it, issue the command:

? WEEKDAYS({08/16/61}, {12/31/61})


The answer displayed in the active window should be 98.

NOTE: This program doe not check for invalid dates, such as {2/30/61}.


Additional query words: VFoxWin FoxMac FoxDos FoxWin 2.50 2.50a 2.50b 2.50c 2.60

Keywords: kbcode KB114354