Using the Difference between dates action - Use the Difference between dates action in the Datetime package to calculate the difference between two date and time values and return the result in a selected time unit.

Automation 360

Use the Difference between dates action in the Datetime package to calculate the difference between two date and time values and return the result in a selected time unit.

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, specify a date and time or a datetime variable that holds the source date.
  • In the Date and time variable to be compared field, specify 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 a number variable to store the result.
  • Click Save.

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. In the navigation menu on the left, 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 4/12/2023 10:45 AM GMT (UTC+0:00)
    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 7/12/2024 10:45 AM GMT (UTC+0:00) in this example.
  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. Double-click or drag the Message box action from the Actions palette.
  12. In the Enter the message to display field, enter the following:

    Difference between:

    Years: $diff-year.Number:toString$

    Month: $diff-month.Number:toString$

  13. When you run the automation, it calculates the difference between the invoice dates and the current date, and the results are displayed as follows:
    Message box output showing the difference between invoice date (2023-04-12) and current date (2024-07-12): Years: 1, Month: 15.