Using the Difference between dates action
- Updated: 2024/07/22
Using the Difference between dates action
The Difference between dates action in the Datetime package enables you to calculate the difference between two dates.
Settings
- Double-click or drag the Difference between dates action from the Datetime node in the Actions palette.
- In the Source date and time variable field, add the source date.
- In the Date and time variable to be compared field,
insert the target date with which you want to compare the source date.Note: If the source date is greater than the target date, then the output is negative.
- In the Time unit field, select one of the following units
in which you want the output to appear.
- Years
- Months
- Weeks
- Days
- Hours
- Minutes
- Seconds
- In the Assign the output to a variable field, select the number variable to specify the variable to which you want to assign the output.
Example
In this example, you will create an automation to compare the invoice dates with the current date and calculate the difference between them.
- Create an automation.
- On the left panel, click Automation.
A list of available bots and forms is displayed.
- Click Create a bot.
- Enter the bot name: Datetime-difference.
- Click Create and Edit.
- On the left panel, click Automation.
- Create the following user-defined variables using the Create
variable (+) icon at the top of the
Variables menu.
Variable name Variable type Default value invoiceDate Datetime Value 4/12/2023 10:45 AM GMT (UTC+0:00) GMT diff-year Number 0 diff-month Number 0 - Double-click or drag the Difference between dates action from the Datetime package in the Actions palette.
- In the Source date and time variable field, enter $invoiceDate$
- In the Date and time variable to be compared field, enter
$System:Date$.Note: You can use the System: Date variable to get the current date. In this example, the System: Date value is considered as 7/12/2024 10:45 AM GMT (UTC+0:00) GMT
- In the Time unit field, select Years.
- Double-click or drag another Difference between dates action from the Datetime package in the Actions palette.
- In the Source date and time variable field, enter $invoiceDate$
- In the Date and time variable to be compared field, enter $System:Date$
- In the Time unit field, select Months.
- To print the values, double-click or drag the Message box
action. In the Enter the message to display field, enter
the following:
Difference between:
Years: $diff-year.Number:toString$
Month: $diff-month.Number:toString$
- When you execute the automation, it calculates the difference between the invoice dates and the current date, and the results are displayed as follows: