******************************************************************** *** 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