YM: Calculating Elapsed Months

How to:

The YM function calculates the number of months that elapse 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(from_date, to_date, output_format)

where:

from_date

I4YM or I6YYM

Is the start date. If the date is not valid, the function returns a 0.

todate

I4YM or I6YYM

Is the end date. If the date is not valid, the function returns a 0.

output_format

Integer

Tip: If from_date 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.



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