Converting Date and Time field to to hours
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-18-2017 08:34 AM
Hi All,
I have a script
var actualDateTime = new GlideDateTime();
actualDateTime.setDisplayValue(gs.nowDateTime());
var gr = new GlideRecord('change_request');
gr.addQuery('number','CNGXXXXXXX')
//gr.addQuery('approval','requested');
//gr.addQuery('state','IN','1,2');
gr.query();
gs.print(gr.getRowCount());
if (gr.next()){
var impendTime = gr.end_date;
var dur = gs.dateDiff(impendTime, actualDateTime);
var d = dur.getMinutes();
gs.print(impendTime);
gs.print(actualDateTime);
gs.print(dur);
}
I get dur out put in Day HH:MM:SS format. How do I convert dur format to Hours or minutes? Can someone help me with this.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-18-2017 08:49 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-18-2017 09:24 AM
Hi Harsh,
My requirement is if I get dur result as "1 10:00:00". I want to convert this entire duration in to hours that is 24+10+00=34 Hours.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-18-2017 11:53 AM
Check out the `max_unit` dictionary attribute. If you set `max_unit=hours`, you'll see what you want to see.
Docs: Set a duration field value