* * WEEKDAYS.PRG * Return the number of days that are MONDAY - FRIDAY * in the passed date range. * Returns .F. if parameters are not passed properly. * * USAGE: * ?WEEKDAYS({^2004-05-01},{^2004-05-31}) * * OR: * ldFrom = {^2004-05-01} * ldTo = {^2004-05-31} * luWeekdays = WEEKDAYS(m.ldFrom, m.ldTo) * IF m.luWeekdays = .F. * ?"Routine failed" * ELSE * ?"The number of weekdays was: " + ALLTRIM(STR(m.luWeekdays)) + "." * ENDIF * * RETURNS: * A numeric value for the number of weekdays. * This also indicates the routine succeeded. * Returns .F. (false) when called with * incorrect parameters. * * lParameters * tdFrom (R) Start of the date range. * tdTo (R) End of the date range. * LPARAMETERS m.tdFrom, m.tdTo *If called with incorrect parameters, RETURN .F. IF NOT (VARTYPE(m.tdFrom)="D" AND VARTYPE(m.tdTo)="D") RETURN .F. ENDIF LOCAL ; m.lnDays, ; m.lnDOW *Determine the total possible number of days. m.lnDays = ABS(m.tdFrom - m.tdTo) + 1 *Determine the number of the day of the week. m.lnDOW = DOW(MIN(m.tdFrom,m.tdTo),2) *Subtract the weekend (Sat/Sun) days. *Also remove the difference between the *"start" date and the closest Monday. RETURN m.lnDays - INT(m.lnDays / 7) * 2 ; - IIF( m.lnDOW = 7, ; SIGN(m.lnDays % 7), ; SIGN(m.lnDOW - 7 + (m.lnDays % 7)) + 1)>>hi all,
>>thisform.text1.value=startdate >>thisform.text2.value=enddate >>thisform.text3.value=thisform.text1.value-thisform.text1.value&&(without friday+saturdy days) >>>>thanks.
>thisform.text1.value=startdate >thisform.text2.value=enddate >thisform.text3.value=CalculateDays(startdate, enddate) > > >FUNCTION CalculateDays(startdate, enddate) > LOCAL cycle, tocycle, testdate, ret_val > ret_val = 0 > tocycle = enddate-startdate > FOR cycle = 0 TO tocycle > testdate = startdate+cycle > IF .NOT. INLIST(DOW(ScanDay,1), 6, 7) && friday, saturday > ret_val = ret_val + 1 > ENDIF > ENDFOR > >RETURN ret_val > >