LPARAMETERS tdStart, tdEnd LOCAL lnStartOffset, lnEndOffset, lnReturn *Adjust the first parameter back to the first Sunday. lnStartOffset = DOW(m.tdStart) - 1 *Adjust the second parameter forward to the following Saturday. lnEndOffset = 7 - DOW(m.tdEnd) *Find the difference between the adjusted parameters. lnReturn = (m.tdEnd + m.lnEndOffset) - (m.tdStart - m.lnStartOffset) + 1 *Determine the number of weekdays. lnReturn = INT(m.lnReturn * .712845) + 1 && 5 / 7 *Now undo the adjustments. lnReturn = m.lnReturn - (m.lnStartOffset - 1) - (m.lnEndOffset - 1) *Coded like this so I can watch lnReturn in the debugger. RETURN m.lnReturn>I needed a solution to determine the number of workdays between two dates and have not been satisfied with the prevalent techniques. The ONLY reliable method required looping, and if the dates were very far apart it would have an impact on performance, There were several calculation methods sugested but when pressed all were found to produce errors.
>LPARAMETERS dDate1, dDate2 >LOCAL LD, hd >LD = MIN(dDATE1,dDATE2) >hd = MAX(dDATE1,dDATE2) >return((WEEK(hd,0,2) - WEEK(ld,0,2)) *5) + ; > IIF(DOW(ld,2) < 6,6-DOW(ld,2),0) + ; > IIF(DOW(hd,2) < 6,DOW(hd,2)-5,0) >>