Date Diff Months
Introduction
This function subtracts one date from another date and returns a numeric value in months, such as 2 months, 5 months, 15 months, or 36 months. While calculating the difference between two dates, you can provide static dates, or the DATEDIFFMONTHS function can dynamically pick dates from attributes and elements.
Use Cases
You can use the DATEDIFFMONTHS function in the following functional scenarios:
- Financial Applications:- You can use this function to determine when the loan was started and calculate monthly-level interest added to the principal amount, and others.
- Project Management Applications:- You can use this function in the project management application to track the project timeline and its current status.
- Payroll and Employment Application:- You can also use this function to calculate the employee’s duration in the organization.
Pre-requisites
- An application page
- An entity
Concepts
To check user’s eligibility crieria, you will define the DATEDIFFMONTHS function in the business rule. The DATEDIFFMONTHS function contains the following parameters:
DATEDIFFMONTHS Function
Input Parameters | Data Type | Description | Sample Value |
date1 | String | This is the first date. The month of the second date is subtracted from the month of the first date. If the first date is greater than the second date, the function returns the positive value. If the first date is less than the second date (future date), the function returns the negative value. | 25-08-2024 |
format1 | Datetime | It represents the date format of the first date. The permissible date formats are: dd-mm-yyyy, dd-mm-yy, yyyy-mm-dd, yy-mm-dd, dd-mm-yyyy hh:mm:ss, and others. | dd-mm-yyyy |
date2 | String | This is the second date. The month of the second date is subtracted from the month of the first date. | 12-04-2025 |
format2 | Datetime | It represents the date format of the second date. The permissible date formats are: dd-mm-yyyy, dd-mm-yy, yyyy-mm-dd, yy-mm-dd, dd-mm-yyyy hh:mm:ss, and others. | dd-mm-yyyy |
Output Value | Description |
A numeric value | The DATEDIFFMONTHS function returns the different between two dates in months. |
Example
This section briefly explains a use case to check the user’s eligibility to reappear in the interview by using the DATEDIFFMONTHS function. To implement this functionality, you have:
- An application page that contains the following elements.
- An Input Field (Label: Address)
- Button (Label: Check Eligibility)
- An entity that contains the following structure:

Usage of DATEDIFFMONTHS Function
- Create the business rule named Eligible_Int. In the business rule, define the logic as follows:

- Create a task group named Display_Message. In the task group, apply the Display Message task and then map the Eligible_Int business rule to the Display Message task.

- Link the Display_Message task group to the onClick event of the Check Eligibility button.
When the application executes the task group, it compares the output of the DATEDIFFMONTHS function with the numeric value 3. If the output is less than or equal to three (3), the application displays the message, “You are not eligible.”
Best Practices
To use the DATEDIFFMONTHS function efficiently, you are recommended the following set of best practices:
- When you use the element and define entities and attributes, use easy-to-remember reference names and names so that you select them without a hassle while mapping in the smart selector.
- To implement a specific application scenario, make a habit of creating a new task group. Do not use a single task group for multiple functional scenarios. This approach makes the application design clutter and complex.
- If you apply multiple tasks in a task group, apply them in a correct sequence so that the required workflow remains intact.
- When you are using entities, use a clean and light-weight JSON structure of the entity.
- Before you use the entity in the application, link it to the data model.
Troubleshooting
If using the DATEDIFFMONTHS function does not return the expected result, check:
- If you define the correct value of dates and their formats.
- If you defined the correct mapping between elements and attributes or selected the correct element to link the related event to the task group.
- Check the sequence of different tasks in the task group.
- Check the value of first and second date to achieve the desired results.
- If you use an API for data manipulation, make sure you establish the correct mapping between the API’s parameters and elements or attributes.
- If you use an API, check its configuration on the vConnect portal.