home *** CD-ROM | disk | FTP | other *** search
- *********
- * Function : INMONTHS
- * By : Tom Rettig
- * Placed in the public domain by Tom Rettig Associates, 10/22/1990.
- *********
-
-
- FUNCTION INMONTHS
- * Syntax: INMONTHS( <start date>, <end date> )
- * Return: <expN> number of months between two dates
- * Note..: Both parameters are <expD>
- * Result is affected by the current state of SET DECIMALS
- *
- PARAMETERS tr_start, tr_end
- DO CASE
- CASE tr_start > tr_end
- * Error -- start date is greater than end date
- RETURN -1
- CASE MONTH(tr_start) == MONTH(tr_end) .and. YEAR(tr_start) == YEAR(tr_end)
- * Start and end dates are the same month and year
- RETURN ( DAY(tr_end) - DAY(tr_start) + 1 ) ;
- / LASTDAY(MONTH(tr_end), YEAR(tr_end))
- OTHERWISE
- * Start and end dates are different MONTHs and/or years
- PRIVATE tr_month
- IF YEAR(tr_start) == YEAR(tr_end)
- tr_month = ( MONTH(tr_end) - MONTH(tr_start) ) - 1
- else
- * Get months from first and last years
- tr_month = ( 12 - MONTH(tr_start) ) + ( MONTH(tr_end) - 1 )
- * Add in between years if any
- IF YEAR(tr_end) - YEAR(tr_start) > 1
- tr_month = tr_month + ( 12 * ( YEAR(tr_end) - YEAR(tr_start) - 1))
- ENDIF
- ENDIF
- RETURN ( (LASTDAY(MONTH(tr_start), YEAR(tr_start)) - (DAY(tr_start)-1));
- / LASTDAY(MONTH(tr_start), YEAR(tr_start))) + tr_month +;
- ( DAY(tr_end) / LASTDAY(MONTH(tr_end), YEAR(tr_end)) )
- * Return statement is based on:
- * first month = ((LASTDAY(MONTH(tr_start), YEAR(tr_start)) ;
- * -(DAY(tr_start)-1))/LASTDAY(MONTH(tr_start),;
- * YEAR(tr_start)))
- * in between months = tr_month
- * last month = ( DAY(tr_end) / LASTDAY(MONTH(tr_end), YEAR(tr_end)) )
- ENDCASE
- * eofunc inmonths
-
-
-