Need help for one of the conversion
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2024 10:12 PM
Hi Everyone,
I need help for one of the conversion.
we are sending data to third party system. we need to send the duration in days.
here we are subtracting auto sys fields as below.
var duration = updated - created,
we need duration in days.
var start_time = new GlideDateTime(grTaskSla.getValue('start_time'));
var end_time = new GlideDateTime(grTaskSla.getValue('end_time'));
var duration = GlideDateTime.subtract(start_time, end_time);
return duration.getDisplayValue();
Please help me how to fetch duration in days
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2024 10:27 PM - edited 02-17-2024 10:28 PM
Use this :
var start_time = new GlideDateTime(grTaskSla.getValue('start_time'));
var end_time = new GlideDateTime(grTaskSla.getValue('end_time'));
var duration = GlideDateTime.subtract(start_time, end_time);
var days = duration.getDayPart();
gs.info('days are :'+ days);
I hope it works for you...
☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2024 04:30 AM
Hi @Sohail Khilji ,
when i tried background script it was returning days.
when i tried in Business rule it was stopping my Business rule triggering.
Do you have any other suggestions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2024 01:30 AM
Hi @Are Kaveri
To calculate the duration between two dates in days using GlideDateTime, you can use the getNumericValue() method to get the duration in milliseconds, then convert it to days. Here's how you can modify your code:
var start_time = new GlideDateTime(grTaskSla.getValue('start_time'));
var end_time = new GlideDateTime(grTaskSla.getValue('end_time'));
var durationInMillis = GlideDateTime.subtract(start_time, end_time).getNumericValue();
var durationInDays = durationInMillis / (1000 * 60 * 60 * 24); // Convert milliseconds to days
return durationInDays;
Please mark as helpfull & Accepted solution if you get it.
BR, Sohith