Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Add Work days to a date
Message
De
05/04/2007 16:19:09
James Blackburn
Qualty Design Systems, Inc.
Kuna, Idaho, États-Unis
 
 
À
05/04/2007 13:43:59
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP1
Divers
Thread ID:
01211326
Message ID:
01212688
Vues:
13
Thanks Marcia and Sergey for your help.



>Anyone have a good program to add the number of workdays to a date without looping through the dates? I am not worried about holidays and such. Just Monday through Friday.
>
>Here is one that handles the holdays too:
>
>
>********************************************************************
>*** Name.....: GETBIZDAYS03.PRG
>*** Compiler.: Visual FoxPro 09.00.0000.2412 for Windows
>*** Function.: Return the date the specified number of business days from the passed date
>*** Returns..: Date
>********************************************************************
>LPARAMETERS tnBizDays, tdDate
>LOCAL ldFrom, lnDOWFrom, lnWeeks, lnActualDays, ldEnd
>
>*** Get the start date
>*** If we are starting on a Saturday, Increment this to Sunday
>ldFrom = IIF( EMPTY( tdDate), DATE(), tdDate )
>ldFrom = IIF( DOW( ldFrom ) = 7, ldFrom + 1, ldFrom )
>
>*** Day of week of base date
>*** using Monday as the first day in the week
>lnDOWFrom = DOW( ldFrom, 2 )
>
>*** Number of weeks to add
>*** unless we are starting on a sunday
>*** because a business week is 5 days which means it ends on Friday
>lnWeeks = IIF( lnDowFrom = 7, INT( tnBizDays / 5 )-1, INT( tnBizDays / 5 ))
>
>*** Number of additional days (modulus)
>lnExtraDays = tnBizDays % 5
>
>*** If we're spanning a weekend, increment the extra days by two
>IF lnExtraDays > 0
>  lnExtraDays = lnExtraDays + IIF( lnExtraDays + lnDOWFrom > 5, 2, 0 )
>ENDIF
>
>*** Adjustment for a starting day on a Sunday
>lnExtraDays = IIF( lnDOWFrom = 7, lnExtraDays + 5, lnExtraDays )
>
>*** Just add the correct number of weeks and any extra days
>lnActualDays = ( lnWeeks * 7 ) + lnExtraDays
>ldEnd = ldFrom + lnActualDays
>
>*** Now see if we have any holidays in this
>*** date range that do not occur on a weekend
>SELECT COUNT( dHolDate ) AS nDays FROM Holiday ;
>  WHERE BETWEEN( dHolDate, ldFrom, ldEnd ) ;
>  AND DOW( dHolDate, 2 ) < 6 ;
>  INTO CURSOR qTmp NOFILTER
>
>IF qTmp.nDays > 0
>  ldEnd = GetBizDays03( qTmp.nDays, ldEnd )
>ENDIF
>
>*** Return the resulting date
>RETURN ldEnd
>
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform