YM: Calculating Elapsed Months
Available Languages: reporting, Maintain
The YM function calculates the number of months between two dates. The dates must be in a year-month format. You can convert a date to this format by using the CHGDAT or EDIT function.
Calculate Elapsed Months
YM(fromdate, todate, output)
where:
I4YM or I6YYM
Is the start date a in year-month format (for example, I4YM). If the date is not valid, the function returns the value 0 (zero).
I4YM or I6YYM
Is the end date in a year-month format. If the date is not valid, the function returns the value 0 (zero).
Integer
Is the name of the field that contains the result, or the format of the output value enclosed in single quotation marks.
Calculating Elapsed Months
The COMPUTE commands convert the dates from year-month-day to year-month format; then YM calculates the difference between the values in the HIRE_DATE/100 and DAT_INC/100 fields:
TABLE FILE EMPLOYEE PRINT DAT_INC AS 'RAISE DATE' AND COMPUTE HIRE_MONTH/I4YM = HIRE_DATE/100; NOPRINT AND COMPUTE MONTH_INC/I4YM = DAT_INC/100; NOPRINT AND COMPUTE MONTHS_HIRED/I3 = YM(HIRE_MONTH, MONTH_INC, 'I3'); BY LAST_NAME BY FIRST_NAME BY HIRE_DATE IF MONTHS_HIRED NE 0 WHERE DEPARTMENT EQ 'MIS'; END
The output is:
LAST_NAME FIRST_NAME HIRE_DATE RAISE DATE MONTHS_HIRED --------- ---------- --------- ---------- ------------ CROSS BARBARA 81/11/02 82/04/09 5 GREENSPAN MARY 82/04/01 82/06/11 2 JONES DIANE 82/05/01 82/06/01 1 MCCOY JOHN 81/07/01 82/01/01 6 SMITH MARY 81/07/01 82/01/01 6
YM calculates the difference between HIRE_MONTH and MONTH_INC and stores the results in a column with the format I3.
YM(HIRE_MONTH, MONTH_INC, 'I3')