How to get days from duration
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2017 04:21 AM
Hi All,
I need to get days from duration, I have written the below query and getting the result as "18 Hours 12 Minutes". How do I get the days out of it.
As I'm using scoped application I'm using GlideDateTime.
var gr=new GlideRecord('abc');
gr.query();
if(gr.next()){
var gdt1 = new GlideDateTime();
var gdt2 = new GlideDateTime(gr.u_xyz.sys_created_on);
var dur = new GlideDuration();
var dur = GlideDateTime.subtract(gdt1, gdt2); //the difference between gdt1 and gdt2
var duration= dur.getDisplayValue();
var daysSplit = duration.split('Days');
gs.info("daysSplit"+daysSplit[0]);
}
Thanks,
Sowmya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2017 04:31 AM
Hi,
You can calculate the days from duration using the below code:
var curr = duration.dateNumericValue(); // Replace "duration" with your variable Name or fetch current.field_name
var totalMs = curr + 24*60*60*100; // totalMs is the result in days.
Hope this helps. Mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2017 04:36 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2020 09:50 AM
The GlideDuration class has a getDayPart() method.