- 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.
- 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
- 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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2025 08:59 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2025 09:06 PM
Hello @samadam , You can use below script to get the result in days. Since you may not get the result always more than 365 days, its better of do a check and convert those days to years, if required. otherwise you can show the days:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2025 09:20 PM
try script shared by Sunil and share us the updates
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader