Skip to content

Commit 8cbb885

Browse files
authored
Create checkdateover90.js
1 parent a63a20a commit 8cbb885

File tree

1 file changed

+20
-0
lines changed
  • Core ServiceNow APIs/GlideDateTime/Check Record Creation over 90 days and output age

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//the pastDateString variable can contain a date-time which you received by querying any particular record's sys_created_on field or any other relevant field. Here I'm hard-coding a value.
2+
3+
var pastDateString = '2025-05-01 10:00:00'; //input date and time
4+
var ageThresholdDays = 90;
5+
6+
var gdtPast = new GlideDateTime(pastDateString);
7+
var gdtNow = new GlideDateTime();
8+
var duration = GlideDateTime.subtract(gdtPast, gdtNow);
9+
var durationMs = duration.getNumericValue();
10+
11+
//Calculate the total days (1 day = 86,400,000 milliseconds)
12+
var totalDaysOld = Math.floor(durationMs / 86400000);
13+
14+
var isOlderThanThreshold = false;
15+
if (totalDaysOld > ageThresholdDays) {
16+
isOlderThanThreshold = true;
17+
}
18+
19+
gs.info("Record Age (Days): " + totalDaysOld);
20+
gs.info("Older than " + ageThresholdDays + " days? " + isOlderThanThreshold);

0 commit comments

Comments
 (0)