Days Dif From Now

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

Introduction

This function calculates the time difference in days by performing the subtraction between the current day and the user-defined day. It picks the current day (date) from the user’s system or device (for example, laptop or mobile phone). The user-defined day can be a date that the user enters in the element, or the function’s algorithm can pick the date from the code of the API or entity’s attribute.

You can use this function in several use cases related to the application development. You can use it to check the age-specific eligibility criteria or calculate the time difference between the current bill payment and the last bill payment.

Prerequisite

Application Page

Assume you have an application where you want to get the data from the user related to his or her personal information and last interview date. On the application page, you have the following elements:

  • Input Field (Label: Full Name)
  • Input Field (Label: Last Interview Date)
  • Button (Label: Submit)

On the application page, do property-level changes in the properties of the Last Interview Date input field.

To change the properties:

  1. On the application page, click the Last Interview Date input field to display the Input Field panel.
  2. In the Input Field panel, click the Input Type list, and then select Regex to display Regex Type list.
  3. Click the Regex Type list and then select Date.
  4. In the Message On Regex Failure box, enter the error message: Please enter date in dd/mm/yyyy format.
  5. After you enter the error message, click Apply to configure the Last Interview Date field.

After you configure the Last Interview Date input field, it will display the error message if the user does not enter the date in dd/mm/yyyy format.

Defining Entity

The next function that you will perform is to create an entity with the key/value pair. Assume you create an entity with the following small structure:

Note:- To know more about creating an entity, click here.

In the date_handler entity, the output parameter will store the output returned by the DAYSDIFFROMNOW function.

Concept

After you design an application page and create an entity to store the output of the DAYSDIFFROMNOW function, you need to implement the DAYSDIFFROMNOW function in a task group. You can configure the task group as follows:

Configuring a Task Group

To configure the task group:

  1. On the vDesigner module’s dashboard, see the left navigation panel.
  1. Put the mouse pointer on the left panel to expand it.
  2. In the left panel, click Task Groups to display the Task Groups page.
  3. On the Task Groups page, either click Create Task Group to create a new task group or double-click the name (for example, DateTime_Diff_Tskgp) of the existing task group to open the <<task group name >> page.

Note:- To know more about creating a new task group, click here.

  1. On the <<task group name >> page, in the Task tab, search and find the Copy Data task.
  1. After you find the Copy Data task, drag it to the Execution panel.
  2. Under Copy Data, in the Copy Data box, click the application tree icon( ) to display the Copy Data panel.
  3. In the Copy Data panel, click in the Copy From box to display the Search box and a group of tabs.
  1. In the group of tabs, scroll right and then click the Functions tab.
  2. In the Search box, enter getenumobj to display the GETENUMOBJ function.
  1. In the list, select the DAYDIFFROMNOW function to display it with the datetime and format parameters.
  2. In the DAYDIFFROMNOW function, click the datetime parameter to display the Search box and a group of tabs.
  3. In the group of tabs, click the Element tab to search the reference name of the element.
  1. In the Search box, enter the element’s reference name (for example, InputField_lastinterviewdt) so that the application picks the data from the element.
  1. In the DAYSDIFFROMNOW function, click the format parameter and then enter dd/mm/yyyy in the place of the format parameter.
  1. Click in the Copy To box to display the Search box and a group of tabs.
  2. In the group of tabs, click the Entity tab.
  3. In the Search box, enter the entity’s name to store the data in it.
  1. In the list, select the entity (for example, date_handler) to store the DAYSDIFFROMNOW function’s output in it.
  1. After you define the condition in the Copy Data panel, click Select to select it.
  2. In the <<task group name>> page, click Save to configure the task group.

Note:- If you store the DAYSDIFFROMNOW function’s output in the element in the place of an entity, configure the Reload task after the Copy Data task. If you do not configure the Reload task after the Copy Data task, the application will not display the element that contains the output.

After the user enters a date in the Last Interview Date box and then clicks Submit, the application executes the Copy Data task in the DateTime_Diff_Tskgp task group. The Copy Data task copies the output of the DAYSDIFFROMNOW function to the output parameter in the date_handler entity.

This section describes how you can use the DAYSDIFFROMNOW function to calculate the difference between the user-defined date and the current date. You can also use this function and its output to validate a user action against the defined condition. Conclusively, you can use it in several functional scenarios. For instance:- You can use it to check the last date of the bill payment.

The following screen contains a sample algorithm that checks the difference between two dates against a static value.

Another Use Case to Use DAYSDIFFROMNOW Function

The above screen capture contains a condition. You can define this condition in a business rule. In the When block, you need to select the DAYSDIFFROMNOW function. The DAYSDIFFROMNOW function contains a reference point: Date.events[0].date. By using this reference point, the application will pick the value of the date attribute in the events array. The events array contains a collection of key/value pairs.

When a user performs the related function, the application picks the value of the date attribute at the zeroth index. Thus, the DAYSDIFFROMNOW function subtracts the picked date from the current date and then returns the output. The user’s action satisfies the condition if the out put of the DAYSDIFFROMNOW function is greater than and equal to forty days (40 days).

You can use this condition to display a message to the user or define a specific application behavior after the user’s action satisfies the condition.

Linking Task Group to Element

After you successfully configure the DAYSDIFFROMNOW function in the task group, you need to link the task group to an element. After the application user performs the function on the linked element, the application executes the task in the task group and then generates the output.

To link the task group to the element:

  1. On the application page, click the element (for example, Submit button) to link it to the DateTime_Diff_Tskgp taskgroup.
  2. After you click the element, the Button panel comes into view.
  3. In the Button panel,  see the Events icon ().
  4. Click the Events icon to display a list of events.
  5. In the list of events, see the onClick event.
  6. To the right of the onClick event, click the Add Task Group icon () to display the Event Configuration page.
  7. On the Event Configuration page, under Task Group, search and find the task group (for example, DateTime_Diff_Tskgp) that you want to map to the onClick event.
  8. After you find the DateTime_Diff_Tskgp task group, drag it to the Execution panel.
  1. After you drag the task group, it displays the task or list of tasks that you configured under it.
  1. On the Event Configuration page, click Save to link the task group to the Submit button.

The End Result

When the application user enters the last interview date in the Last Interview Date input field and clicks the Submit button, the application executes the DateTime_Diff_Tskgp task group. In the DateTime_Diff_Tskgp task group, the Copy Data task contains the DAYSDIFFROMNOW function that picks the date (for example, 17/08/2024) from the Last Interview Date field and then subtracts it from the current date. After the function performs the subtraction, the Copy Data task stores the output in the date_handler entity.

Later, you can use the output stored in the date_handler entity to check if the user is eligible to reappear in the interview.

Examples and Use Cases

You can use the DAYSDIFFROMNOW function in the following use cases and scenarios:

  • Calculating the difference between two dates
  • Calculating a specific timeframe
  • Checking if a user selected the right date in the calendar
  • Checking the date when the user performed the activity
  • Checking last date of an activity, such as last date of bill payment
  • Capturing the occurrence of the user’s activity on the periodical basis

Best Practices

To use the DAYSDIFFROMNOW function smoothly during the application development in the vDesigner module, you are recommended the following set of best practices:

  • In the DAYSDIFFROMNOW function, define the date format supported by the vDesigner module.
  • When you are using the element for data manipulation, use the reference name of the element that you can easily remember and search.
  • When you are using entities, use clean and relevant JSON structure of the entity.
  • Before you use the entity in the application, link it to the data model.
  • If you are using the DAYSDIFFROMNOW function to perform the subtraction between the future date and the current date, it will generate the output in negative value (for example, -12 days, -23 days, etc.).

Troubleshooting

  • If using the DAYSDIFFROMNOW function does not return the expected result or generates an error, check the related condition in the task or business rule. Also check if you established the correct mapping between elements, entities, and other such types of objects and variables.
  • If application generates the error, use the debugger module to fix the error quickly.
Was this article helpful?
YesNo