home *** CD-ROM | disk | FTP | other *** search
- *********
- * Function : INWKDAYS
- * By : Leonard Zerman
- * Placed in the public domain by Tom Rettig Associates, 10/22/1990.
- *
- * Syntax: INWKDAYS( <start date>, <end date> )
- * Return: <expN> number of weeks between two dates
- * Note..: Both parameters are <expD>
- * Includes both days.
- *********
- FUNCTION INWKDAYS
- PARAMETERS tr_start,tr_end
- MEMVAR tr_comp, tr_days, tr_weekdays
- PRIVATE tr_comp, tr_days, tr_weekdays
- tr_comp = 0
- DO CASE
- CASE tr_start > tr_end
- * Error -- start date is greater than end date
- RETURN -1
- CASE tr_start == tr_end .AND. .NOT. ISWKEND( tr_end )
- RETURN 1
- CASE ( tr_start == tr_end .AND. ISWKEND( tr_end ) ) .OR. ;
- ( ISWKEND(tr_start) .AND. ISWKEND( tr_end ) .AND. ;
- ( tr_end - tr_start ) == 1 )
- RETURN 0
- ENDCASE
- IF ( tr_end - tr_start < 6 )
- DO WHILE ( tr_start <= tr_end )
- IF .NOT. ISWKEND( tr_start )
- tr_comp = tr_comp + 1
- ENDIF
- tr_start = tr_start + 1
- ENDDO
- RETURN(tr_comp)
- ENDIF
- DO WHILE ISWKEND( tr_start ) && If start is on a weekend skip past it
- tr_start = tr_start + 1
- ENDDO
- DO WHILE DOW( tr_start ) # 2 && If start is on any day but Monday
- tr_start = tr_start + 1 && compensate to monday w/o weekends
- IF .NOT. ISWKEND( tr_start )
- tr_comp = tr_comp + 1
- ENDIF
- ENDDO
- DO WHILE ISWKEND( tr_end ) && do the same for the end date
- tr_end = tr_end - 1
- ENDDO
- DO WHILE DOW( tr_end ) # 2
- tr_end = tr_end -1
- IF .NOT. ISWKEND( tr_end )
- tr_comp = tr_comp + 1
- ENDIF
- ENDDO
- tr_days = ( tr_end - tr_start ) + 1
- tr_weekdays = tr_days - ( INT( tr_days / 7 ) * 2 )
- RETURN ( tr_weekdays + tr_comp )
- * eof inwkdays *
-
-