Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**Usecase**:
This piece of code can be used to check whether a record was created more than 90 days ago or not.
It returns an output of true/false as well as the actual age (in days) of the record.

**Type**:
Background Script

**How it works**:
There is a pastDateString variable which can contain a date-time which you received by querying any particular record's sys_created_on field or any other relevant field.
In the actual code I have hard-coded a value to be used as an example.
-There are two gliderecord objects to store the current date as well as past date
-GlideDateTime.subtract() is used to calculate the time difference as a GlideDuration object
-The time duration in milliseconds is converted to days by dividing with 86400000(milliseconds in a day)
-Comparison is done between the results
-The final age of the record and true/false result of the comparison is the output.
[Note: Output may vary according to timezones]

**Example**:
pastDateString = 2025-05-01 10:00:00
Output:

Record Age (Days): 165
Older than 90 days? true
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//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.

var pastDateString = '2025-05-01 10:00:00'; //input date and time
var ageThresholdDays = 90;

var gdtPast = new GlideDateTime(pastDateString);
var gdtNow = new GlideDateTime();
var duration = GlideDateTime.subtract(gdtPast, gdtNow);
var durationMs = duration.getNumericValue();

//Calculate the total days (1 day = 86,400,000 milliseconds)
var totalDaysOld = Math.floor(durationMs / 86400000);

var isOlderThanThreshold = false;
if (totalDaysOld > ageThresholdDays) {
isOlderThanThreshold = true;
}

gs.info("Record Age (Days): " + totalDaysOld);
gs.info("Older than " + ageThresholdDays + " days? " + isOlderThanThreshold);
Loading