monthsDiff()
Table of Contents
Overview
The monthsDiff() function takes startDateTimeValue and endDateTimeValue as arguments. It returns the number of months between the given date-time values.
Note: The difference between monthsDiff function and monthsBetween function is that the monthsBetween function considers a month as 30 days. So, let's say the start date is specified as 01-Feb-2020 and the end date is specified as 01-Mar-2020, the monthsBetween function will return 0 (since the difference in days is less than 30). The monthsDiff function returns 1 in this case since this function considers a month depending on the number of days in it.
Return Type
Syntax
<variable> = <startDateTimeValue>.monthsDiff(<endDateTimeValue>);
(OR)
<variable> = monthsDiff(<startDateTimeValue>,<endDateTimeValue>);
Parameter | Description | Data type |
---|---|---|
<variable> | Variable which will contain the returned number. | NUMBER |
<startDateTimeValue> | The starting date-time value. | DATE-TIME |
<endDateTimeValue> | The ending date-time value. | DATE-TIME |
Note:
- The time value is not taken into account while using this function.
- Please refer this help document to learn about the supported date-time formats.
Examples
startDate = '31-Dec-1989';
endDate = '01-Jan-1990';
newEndDate = '01-Feb-1990';
numberOfMonths= monthsDiff(startDate, endDate); // returns 0
numOfMonths = monthsDiff(startDate, newEndDate); // returns 1
endDate = '01-Jan-1990';
newEndDate = '01-Feb-1990';
numberOfMonths= monthsDiff(startDate, endDate); // returns 0
numOfMonths = monthsDiff(startDate, newEndDate); // returns 1
startDate = '01-Feb-2020';
endDate = '01-Mar-2020';
info monthsDiff(startDate, endDate); // returns 1
endDate = '01-Mar-2020';
info monthsDiff(startDate, endDate); // returns 1