Date Diff Minutes

This post is referring to Vahana 2 (beta version). To check the document for production, please go to vDesigner-v1.0

Introduction

This function subtracts one date from another date and returns a numeric value in minutes, such as 2 minutes, 5 minutes, or 10 minutes. While calculating the difference between two dates, you can provide static dates, or the DATEDIFFMINUTES function can dynamically pick dates from attributes and elements.

Use Cases

The DATEDIFFMINUTES function can be used in the following use cases:

  • To calculate the down time of a system or service
  • To check how much time a system takes to respond to a ticket and event
  • To calculate how long a user is active on the application or website
  • To define a time frame after which an OTP will expire
  • To charge client based on the time-based billing

Pre-requisite

  • An Application Page
  • An Entity
  • Task Groups
  • Business Rule

Concepts

This section describes how to use the DATEDIFFMINUTES function to calculate the time to display the Resend OTP button and hide the Timer element after it completes its time.

DATEDIFFMINUTES FUNCTION

Input ParametersData TypeDescriptionSample Value
date1StringThis parameter represents the first date. This function subtracts the second date from the first date.13-06-2025 15:44:30
format1DatetimeIt represents the date format of the first date. The permissible date formats are: dd-mm-yyyydd-mm-yyyyyy-mm-ddyy-mm-dddd-mm-yyyy hh:mm:ss, and others.DD-MM-YYYY HH:MM:SS
date2StringThis parameter represents the second date. This function subtracts the second date from the first date.13-06-2025 15:47:30
format2DatetimeIt represents the date format of the first date. The permissible date formats are: dd-mm-yyyydd-mm-yyyyyy-mm-ddyy-mm-dddd-mm-yyyy hh:mm:ss, and others.DD-MM-YYYY HH:MM:SS
Output ValueDescription
A numeric valueThe DATEDIFFMINUTES function returns the different between two dates in minutes.

Example

This section describes how to use the DATEDIFFMINUTES function to calculate a timeframe between two different datetime values. After this timeframe, the application page displays the Resend OTP button and hides the Timer element.

To implement this functionality:

  1. Create an application page that has the following:
    • An OTP element
    • A Timer element with count time 3 minutes (format: mm:ss)
    • Two buttons (Labels: Send OTP and Resend OTP)
  2. Two entities (OTP and OTP_ENT)
    • The OTP entity stores the data related to the OTP.
    • The OTP_ENT contains two attributes: Send_OTP_Time and Timer_Comp_Time. These attributes store datetime values to calculate the time difference. The DATEDIFFMINUTES function picks the minute values from these attributes and then calculates the difference.
  3. Two tasks groups as follows:
    • OTP_Mgmt_Tskgp:- This task group is mapped to the Send OTP button. It contains the following tasks:
      • Invoke API (Sends OTP to the end-user)
      • Visible/Invisible (Hides Send OTP button and displays the Timer element)
      • Timer (Starts the Timer element with the 3 minutes count time)
      • Copy Data (Captures the current date and time and then stores it in the Send_OTP_Time attribute)
    • OTP_Mgmt_Tskgp2:- This task group is mapped to the Timer element. It contains the following tasks:
      • Copy Data (Captures the current date and time and then stores it in the Timer_Comp_Time attribute)
      • Delay (Delays the next function to manage application’s latency)
      • Visible/Invisible (Hides the Timer element and then displays the Resend OTP button)
  4. A business rule named DateDifference time_min calculates the time in minutes by subtracting a datetime value from another datetime value.

On the application page, when a user clicks the Send OTP button, it executes the Invoke API task to send an OTP to the user. After the user clicks the Send OTP button, the application hides the Send OTP button, displays the timer element, and stores the current date and time in the Send_OTP_Time attribute.

After the timer element completes its defined count time of 3 minutes, the application hides the timer element, stores the current time in the Timer_Comp_Time attribute, and displays the Resend OTP button. To display the Resend OTP button, the DATEDIFFMINUTES function calculates the time difference between values stored in the Send_OTP_Time and Timer_Comp_Time attributes. If this difference is greater than three minutes, the application displays the Resend OTP button.

Best Practices

To use the DATEDIFFMINUTES 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 DATEDIFFMINUTES function does not return the expected result, check the following:

  • 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.
Was this article helpful?
YesNo