YM: Calculating Elapsed Months

How to:

The YM function calculates the number of months between two dates. The dates must be in year-month format. You can convert a date to this format by using the CHGDAT or EDIT function.


Top of page

x
Syntax: How to Calculate Elapsed Months
YM(fromdate, todate, output)

where:

fromdate

I4YM or I6YYM

Is the start date in year-month format (for example, I4YM). If the date is not valid, the function returns the value 0 (zero).

todate

I4YM or I6YYM

Is the end date in year-month format. If the date is not valid, the function returns the value 0 (zero).

output

Integer

Tip: If fromdate or todate is in integer year-month-day format (I6YMD or I8YYMD), simply divide by 100 to convert to year-month format and set the result to an integer. This drops the day portion of the date, which is now after the decimal point.



Example: Calculating Elapsed Months

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')

iWay Software