Choose where you’d like to start

monthsBetween()

Overview

The monthsBetween() function takes startDateTimeValue and endDateTimeValue as arguments. It returns the number of months between the given date-time values.

Note: The difference between monthsBetween function and monthsDiff 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

  • Number

Syntax

<variable> = <startDateTimeValue>.monthsBetween(<endDateTimeValue>);

(OR)

<variable> = monthsBetween(<startDateTimeValue>,<endDateTimeValue>);
ParameterDescriptionData 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.

A runtime error will be encountered in Zoho Creator if:

  • the hour value, or minute value, or second value, is specified in more than 2 digits.
  • the date value exceeds the number of days in that month.
  • an incorrect month value is specified.
  • the year value has more than 4 digits.

Examples

startDate = '31-Dec-1989';
endDate = '01-Jan-1990';
newEndDate = '01-Feb-1990';
numberOfMonths= monthsBetween(startDate, endDate);              // returns 0
numOfMonths = monthsBetween(startDate, newEndDate);           // returns 1
 
startDate = '01-Feb-2020';
endDate = '01-Mar-2020';
info monthsBetween(startDate, endDate); // returns 0

Get Started Now

Execute