Hours Dif From Now

The HoursDifFromNow function calculates the difference in hours between the current time and a given input date-time. It is useful for tracking time-based conditions, session durations, and expiry logic.

When to use:

Use this function when you need to:

  • Track hourly differences since a recorded event (e.g., time of login, data submission).
  • Trigger logic or workflows based on the passage of time measured in hours.
  • Enforce restrictions on short-term tasks such as retry windows, approval timeframes, or session locks.

Common Use Cases

  • Session Expiry Tracking: Auto-lock or invalidate user sessions after a set number of hours.
  • Document Access Timing: Restrict access to a document link after it has been active for a few hours.
  • Service Timeouts: Trigger alerts or follow-ups if a service or task hasn’t been completed within a specific hour window.
  • Reminder Scheduling: Send reminders a few hours before or after a scheduled task (e.g., appointment reminders).

Concept

You will typically use the function within the Smart Selector, which has various function tabs. By typing “HOURSDIFFROMNOW” in the search bar, you can select it and define its parameters.

Parameters:

DatetimeThis 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)
FormatThis 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:

Scenario: Suppose your app has a “Request Loan” button that navigates you to the loan application page only after 1 hour of first-time login, allowing enough time for initial data sync or eligibility verification. Before 1 hour, it will display a message.

Pre-Requisite:

  • Basic Understanding of Tasks and Entity.
  • Request Loan‘ button element.

You have to do three steps:

  1. Creating an Entity
  2. Creating a Business Rule
  3. Create a Message
  4. Creating a Task Group

Create an Entity

Create a JSON entity that stores the first time login timestamp:

From here, the application will fetch the data and compare using the BR and the function.

Create a Business Rule

BR 1. If this condition is true, the user will see a message.
In the business rule, you will define a condition using the function. Create a BR (e.g., HoursDifFromNow) that checks if one hour has not passed after the first time login.

Left SideOperatorRight Side
DescriptionSelect the HOURSDIFFROMNOW function and define its parametersMore than or Equal (=<) Select the Static Function and define its parameter
ParametersDateTime: FirstTimeLoginTimeStamp attribute.

Format: DD-MM-YYYY HH:mm:ss
CastTo: Number

Value: 1

BR 2. If this condition is true, the user will be navigated to the Loan Application Page.

In the business rule, you will define a condition using the function. Create a BR (e.g., HoursDifFromNow) that checks if one hour has elapsed after the first time login.

Left SideOperatorRight Side
DescriptionSelect the HOURSDIFFROMNOW function and define its parametersMore than (>)Select the Static Function and define its parameter
ParametersDateTime:FirstTimeLoginTimeStamp attribute.Format: DD-MM-YYYY HH:mm:ssCastTo: NumberValue: 1

Create a Message

Create a message (e.g. HoursDiff) with:

  1. Title: Verification is in process.
  2. Message: Please wait, document verification is in process. You may apply after 1 hour of the first time login.

Create a Task Group

The task group defines what happens when the user performs certain action:

  1. Create a Task Group, e.g. HourDifFromNow
  2. Drag Display Message task to the execution box:
    • Select the message created above, e.g. HoursDiff.
    • Select BR1 as the business rule / condition.
  1. Drag Navigate Task to the execution box:
    • Select ‘Apply Loan’ as destination screen.
    • Select BR2 as the business rule / condition.

Best Practices

  1. Use a consistent date-time format (e.g., DD-MM-YYYY HH:mm:ss) for both storing and evaluating timestamps.
  2. Use meaningful business rule names (e.g., BR_HourDiff_Eligible, BR_HourDiff_NotYet) for clarity.
  3. Avoid hardcoding time thresholds; store them in a config entity to allow easy updates.
  4. Account for timezone differences if applicable
    If your app serves users across different time zones, normalize timestamps to a common timezone before applying HoursDifFromNow.
Was this article helpful?
YesNo