Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Calculating work days
Message
De
29/02/2000 09:24:37
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00338999
Message ID:
00339050
Vues:
24
Hi Michael.

>> I'm looking for a function to calculate the number of work days; Monday - Friday, between two dates. I have an application that must do tons of these calculations so speed is quite important. ie - no looping through the date range to count the work days. <<

Here is one that gives you the date that is n business days from the date that you pass to it. Maybe it will give you some ideas.
**********************************************************************
* Program....: BusinessDays
* Compiler...: Visual FoxPro 06.00.8492.00 for Windows
* Abstract...: Given a start date and a number of days, returns the 
* ...........: date that is that number of days business in the future
**********************************************************************
FUNCTION BusinessDays ( tdStartDate, tnNumberOfDays )
LOCAL lnCnt, ldDate, llOK, llUsed 

*** Make sure we have the Holidays table available
IF !USED( 'Holidays' )	
  USE Holidays In 0
  llUsed = .F.
ELSE
  llUsed = .T.
ENDIF
SELECT Holidays
SET ORDER TO dHoliday

ldDate = tdStartDate			
FOR lnCnt = 1 TO tnNumberOfDays
  ldDate = ldDate + 1
  llOK = .F.
  DO WHILE !llOK
    *** If current date is a Saturday, go to Monday
    IF DOW( ldDate ) = 7
      ldDate = ldDate + 2
    ELSE
      *** If current date is a Sunday, go to Monday
      IF DOW( ldDate ) = 1
        ldDate = ldDate + 1
      ENDIF
    ENDIF
    *** OK, now check for Holidays
    IF !SEEK( ldDate, 'Holidays', 'dHoliday' )
      llOK = .T.
    ELSE
      ldDate = ldDate + 1
    ENDIF
  ENDDO
ENDFOR

IF !llUsed
  USE IN Holidays
ENDIF
	
RETURN ldDate
Marcia
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform