Skip to content

Commit 2af3076

Browse files
authored
Add date difference calculation function
This script calculates the difference in days between two dates using GlideDateTime.
1 parent 34e4082 commit 2af3076

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Author: Harish Kothandapani
2+
// Purpose: Calculate difference in days between two dates
3+
4+
function getDateDifferenceInDays(startDate, endDate) {
5+
try {
6+
var gdtStart = new GlideDateTime(startDate);
7+
var gdtEnd = new GlideDateTime(endDate);
8+
var diff = gs.dateDiff(gdtStart.getDisplayValue(), gdtEnd.getDisplayValue(), true);
9+
// gs.dateDiff returns seconds when third param = true
10+
return Math.floor(diff / (60 * 60 * 24)); // convert seconds to days
11+
} catch (e) {
12+
gs.error('Error calculating date difference: ' + e.message);
13+
return null;
14+
}
15+
}
16+
17+
// Example usage:
18+
// gs.info(getDateDifferenceInDays('2025-10-01 00:00:00', '2025-10-16 00:00:00'));

0 commit comments

Comments
 (0)