Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2025 08:43 PM
I am trying to find difference between current date and start dates in years, this is in scoped applications. Datediff is not working. Any other ways to get this?
Solved! Go to Solution.
1 ACCEPTED SOLUTION
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2025 08:55 PM
Please try below approach
var startDate = new GlideDateTime("2020-02-19"); // Replace with actual field value
var currentDate = new GlideDateTime();
var diffMillis = currentDate.getNumericValue() - startDate.getNumericValue();
var diffYears = diffMillis / (1000 * 60 * 60 * 24 * 365);
gs.info("Difference in years: " + diffYears);Please mark correct/helpful, thanks
6 REPLIES 6
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2025 09:28 PM
Hi @samadam i have try in background script for incident table to check it work . make changes as per your requirement
var gr = new GlideRecord('incident');
gr.query();
while (gr.next()) {
if (!gr.opened_at.nil()) {
var startDate = new GlideDateTime(gr.opened_at);
var currentDate = new GlideDateTime();
var startYear = parseInt(startDate.getYearUTC(), 10);
var currentYear = parseInt(currentDate.getYearUTC(), 10);
var difference = currentYear - startYear;
gs.info('Incident: ' + gr.number + ' | Year Difference: ' + difference);
}
}
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2025 09:40 PM
Thank you so much, that worked
