logo

NJP

Date difference in Flow Designer

Import · May 14, 2022 · article

Story-------Every now and then I encounter questions in the community regarding date comparison of some sort, very often the question is to find the difference in days between two dates, and often the answer is a script using various GlideDateTime functions.

Using Flow designer is no exception, there is also a need for date comparison there, and the answer is often using some inline scripting.

So in the spirit of Flow designer I've built an reusable action to make it easier to retrieve these values, and avoid scripting in numerous situations.

One specific scenario that I've also wanted to address is the problem when using if/else Flow logic, there is no way to make an if statement like the following; if (datetime1 is relative x days before datetime2)

Details

---------

-You can either input one or two datetime objects to the action. If only one input is submitted, the action assumes/calculates the difference between the given datetime, and the current system datetime.

-The action always returns a zero or positive integer values on the difference in days/hours/and so on (ex. no negative numbers if the start date is after the end date).

Sample usage image below, and the complete XML is attached.

image

image

Install steps

----------------

  • Navigate to .
  • Click the Import Update Set from XML link.
  • Click Choose File and select the Date_Comparison_Flow_Designer.xml file.
  • Click Upload.
    The update set appears in the Retrieved Update Set related list in the Loaded state.
  • Click Preview Update Set.
  • Click Commit Update Set.

Labels:

image

View original source

https://www.servicenow.com/community/developer-articles/date-difference-in-flow-designer/ta-p/2296202