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

  1. Double-click or drag the Difference between dates action from the Datetime node in the Actions palette.
  2. In the Source date and time variable field, add the source date.
  3. 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.
  4. 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
  5. 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.

  1. Create an automation.
    1. On the left panel, click Automation.

      A list of available bots and forms is displayed.

    2. Click Create a bot.
    3. Enter the bot name: Datetime-difference.
    4. Click Create and Edit.
  2. 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
  3. Double-click or drag the Difference between dates action from the Datetime package in the Actions palette.
  4. In the Source date and time variable field, enter $invoiceDate$
  5. 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
  6. In the Time unit field, select Years.
  7. Double-click or drag another Difference between dates action from the Datetime package in the Actions palette.
  8. In the Source date and time variable field, enter $invoiceDate$
  9. In the Date and time variable to be compared field, enter $System:Date$
  10. In the Time unit field, select Months.
  11. 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$

  12. When you execute the automation, it calculates the difference between the invoice dates and the current date, and the results are displayed as follows:

    Comparison of invoice dates output