FULLSCREEN CONTENTS Project Home Page
.FUNCTION....: Month Date Arithmetic Functions
.ALIAS.......: MODAARFU
.DISCUSSION..:
Function name is "m" for "month arithmetic".

EXAMPLE: FDATE /Fm /Nnumdays /Adate /Iformat /Oformat

This function adds /N months to /Adate, and produces a date in /Oformat format. It can be used to do monthly subtraction by making the number in the /N parameter a negative number.

.EXAMPLES:

 FDATE /Fm /N1  /A03-15-1992 /Imm-dd-ccyy /Omm-dd-ccyy
         produces:   04-15-1992

 FDATE /Fm /N-1 /A03-30-1991 /Imm-dd-ccyy /Omm-dd-ccyy
         produces:   02-28-1991

 FDATE /Fm /N-1 /A03-30-1992 /Imm-dd-ccyy /Omm-dd-ccyy
         produces:   02-29-1992


.DISCUSSION..:
Note that a too-simple algorithm for month arithmetic can produce non-existent dates. Subtracting a month from March 30, 1991 (as in the second example) could produce a result of February 30, 1991, a date which cannot exist.

Fdate's month arithmetic is more sophisticated than that. If Fdate finds that a simple month-arithmetic operation produces an invalid date, it subtracts the minimum number of days required to produce a valid date.

Thus, in the second example, it produces February 28, 1991, the last date in February, 1991. In the third example, it produces February 29, 1992 because 1992 is a leap year.


Note that telling Fdate to add 12 months to February 29, 1992 produces a result of February 28, 1993, since 1993 is not a leap year. See Peter G. Neumann's INSIDE RISKS column in COMMUNICATIONS OF THE ACM, June 1992 (Vol. 35, No. 6), entitled "Leap-Year Problems":