- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-01-2016 09:01 AM
Since we are unable to have a Service Catalog Variable type as a "Duration" , like we are with field values - I need to convert a duration value to a more readable format.
I have calculated the duration between two GlideDateTime values and have a value of this: "23:24:41";
How do I convert this new value ('23:24:41') to something that would read 23 hours, 24 minutes and 41 seconds?
I could rip it apart with some JavaScript and play around with it that way, but I was wondering if there's a more elegant solution.
Thanks.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-01-2016 09:40 AM
Jamison,
Here is the easiest way to do this. Just put in your value in to the GlideDuartion as shown below and use getDisplayValue()
var duration = new GlideDuration('23:24:41');
duration.getDisplayValue(); //this will give you the required format
You can convert it to Days Hours Minutes by using duration.getDisplayValue()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-01-2016 09:17 AM
Yes, There is existing method. Here is an example, which calculates span,duration and displaying in the descriptive format as you wanted. You can convert below method as you want.
var gdt = new GlideDateTime("2011-08-31 08:00:00"); //Wednesday
var dur = new GlideDuration();
var span = gdt.getSpanTime(3); //how much time since Monday 00:00:00
dur.setValue(span);
gs.addInfoMessage(dur.getDisplayValue());
GlideDateTime - ServiceNow Wiki

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-01-2016 09:40 AM
Jamison,
Here is the easiest way to do this. Just put in your value in to the GlideDuartion as shown below and use getDisplayValue()
var duration = new GlideDuration('23:24:41');
duration.getDisplayValue(); //this will give you the required format
You can convert it to Days Hours Minutes by using duration.getDisplayValue()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-01-2016 10:49 AM
I ended up using this the subtract() method here for the solution:
var start = new GlideDateTime(current.opened_at);
var end = new GlideDateTime(current.u_resolved_at);
var xx = GlideDateTime.subtract(start, end);
gs.log(xx.getDisplayValue(), "JC");
And the output is as expected: 23 Hours 24 Minutes
Thanks.