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:
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:
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:
You have to do three steps:
- Creating an Entity
- Creating a Business Rule
- Create a Message
- 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 Side | Operator | Right Side |
Description | Select the HOURSDIFFROMNOW function and define its parameters | More than or Equal (=<) | Select the Static Function and define its parameter |
Parameters | DateTime: 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 Side | Operator | Right Side |
Description | Select the HOURSDIFFROMNOW function and define its parameters | More than (>) | Select the Static Function and define its parameter |
Parameters | DateTime:FirstTimeLoginTimeStamp attribute.Format: DD-MM-YYYY HH:mm:ss | CastTo: NumberValue: 1 |
Create a Message
Create a message (e.g. HoursDiff) with:
- Title: Verification is in process.
- 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:
- Create a Task Group, e.g. HourDifFromNow
- Drag Display Message task to the execution box:
- Select the message created above, e.g. HoursDiff.
- Select BR1 as the business rule / condition.

- Drag Navigate Task to the execution box:
- Select ‘Apply Loan’ as destination screen.
- Select BR2 as the business rule / condition.

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