Skip to content

Commit cc3ab0f

Browse files
authored
Get days difference action (ServiceNowDevProgram#743)
* Custom action to get the days difference between two dates. * Description for "get days difference" flow action.
1 parent 0a1c248 commit cc3ab0f

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// A custom flow action to get the days difference between two dates using GlideDateTime class.
2+
//Input variable of the action are startDate and endDate. Output variable is difference.
3+
(function execute(inputs, outputs) {
4+
var startDate = new GlideDateTime(inputs.startDate);
5+
var endDate = new GlideDateTime(inputs.endDate);
6+
var startDateInMilliseconds = startDate.getNumericValue();
7+
var endDateInMilliseconds = endDate.getNumericValue();
8+
var timeDifference = endDateInMilliseconds - startDateInMilliseconds;
9+
var daysDifference = Math.ceil(timeDifference / (1000 * 3600 * 24));
10+
outputs.difference = daysDifference;
11+
})(inputs, outputs);
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Get Days Difference
2+
Frequently, in our flow, there's a need to calculate the difference in days between two dates. To address this, I've developed a specialized flow action that facilitates this calculation.

0 commit comments

Comments
 (0)