Years Dif From Now
The YearsDifFromNow
function calculates the difference in full years between a given date and the current system date. It is commonly used to determine durations such as age, account tenure, or time passed since a particular event.
When to Use
Use YearsDifFromNow
when you need to:
- Validate age eligibility for services or schemes.
- Calculate the tenure of accounts or products.
- Determine how long ago an event or date occurred.
This function is ideal for banking and financial workflows that rely on time-based validations or business rules.
Common Use Cases
- Age Restriction Validation
Prevent users under a certain age (e.g., 18 or 21) from accessing specific services like account creation, KYC, or credit card eligibility. - Loan Product Eligibility
Determine if a customer meets the age requirement for a loan scheme by calculating their age from their date of birth. - Investment Maturity Duration
Calculate how many years have passed since the investment start date to check for eligibility for maturity benefits. - Customer Relationship Tenure
Determine how long a customer has been associated with the bank, starting from account opening or onboarding date.
Concept
You will typically use the function within the Smart Selector, which has various function tabs. By typing “YearsDifFromNow” in the search bar, you can select it and define its parameters. The result of the year difference from the current date can be displayed in another field (typically a numeric input). This function has two parameters:
Parameters
Datetime | This defines the source date from which the function will calculate the difference in years compared to the current date. You can enter: – A reference to an element (e.g., DatePicker_StartDate )– Or a JSON path to fetch a value from an entity (e.g., Insurance.policy[0].startDate ) |
Format | This specifies the format of the date being read. The function uses this to correctly parse the input date before calculating the difference. DD, MM, YY, HH, SS, DDD, MMM, YYYY, etc. |
Since this function can be applied across multiple scenarios to show year difference from the current year, we’ll walk through one specific example below:
Display the difference between current year and the year typed by the user in an input field.
Example Scenario: A user selects an estimated date for his Fixed Deposit to mature, so it will display the duration of FD in years in the input field, calculating it from time he is creating the FD on.
Pre-Requisite:
- Basic Understanding of Tasks.
- A screen in vDesigner 2.0 with the following elements:
Element Type | Element Name | Reference Name | Description |
---|---|---|---|
Input Field | Year of Maturity | InputField_FDMaturity | Allows user to type the year when they the FD to get matured. |
Input Field | Duration | InputField_Duration | Displays FD duration in years. Set input type to Number . |
For InputField_FDMaturity
element:
– Input Type: Regex
– Regex Type: Custom
– Enter Regex: ^\d{4}$
– Message on Regex Failure: Invalid Format
This ensures only valid 4-digit years are accepted.

After you these two Input Fields to the vDesginer Canvas, you have to do only two steps:
- Creating a Task Group
- Linking of Task Group.
Creating a Task Group
The task group defines what happens when user perform certain action:
- Drag Copy Data Task to the execution panel and do the following:
Copy From | Copy To |
1. Select YEARSDIFFROMNOW function. 2. Define its Format (e.g., YYYY). 3. In the Datetime parameter, select the element you want to perform this function on (e.g., InputField_FDMaturity). | Select the element where you want to show the result of function. (e.g., InputField_Duration) |
- Reload the elements.

Linking of Task Group
Link the Task Group to the “Year Of Maturity” input field using the On Completion event. This ensures that once the user finishes entering the year, the associated task is triggered. The result of the task will then be displayed in the “Duration” input field.
Final Result
Now whenever user enters an year in the “Year of Maturity” input field, YearsDifFromNow
will calculate the year difference from the currrent year and display it in the “Duration” input field.
Another Example Scenario:
Let’s say you have a field or data structure that contains the insurance start date:

We want to check whether 3 full years have passed since Insurance.policy[0].startDate
. If true, it means the insurance has expired and we can notify the user.

This returns true
if 3 or more years have passed. Link this rule to a Task Group with a Display Message task (e.g., “Your insurance has expired”). Trigger it using an event like onClick
on a button or onCompletion
of a input date field.
Best Practices:
- Use consistent date formats to ensure accurate parsing and calculation.
- Validate user-entered dates using regex or format settings to prevent invalid input.
- Use structured entity paths (e.g.,
Insurance.policy[0].startDate
) to reliably reference dates in conditions and tasks. - Reload entities when date values are updated during runtime to reflect the latest changes.