How to convert duration which is of string type to hours format
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-08-2020 11:04 PM
Hello All,
Three Fields A,B, C.. Based on the reason field duration value is added into each field. with type "1 hour 44 minutes" e.g
Now I want to go on adding all duration into separate new field 'D'.
Values are in string format for records while saved..by using duration.getDisplayValue().
For adding two duration I can use duration.add(duration2).
but how to add string type i.e let's say 5 minutes OR 1 hour 22 minutes type of duration.
OR how do I convert duration of string type i.e 22 hours 47 minutes into actual hh:mm:ss format?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-08-2020 11:09 PM
please share what values would be present?
there could be values in different format some in minutes, some in hours etc
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-09-2020 12:30 AM
Hello Ankur,
Let's say,
Field A = 2 Hours 52 Minutes, when records was in A reason the total time is this, later, same records was in B reason hence, total duration for Field B = 5 minutes for Reason B, later, same records was in C reason hence, for field c duration was 2 days 11 hours. , for Reason C
when reason is changing I go on adding a total value of how much time it was in the reason state. SO I need to go on adding.
I am calculating this duration using
var dur1 = new GlideDateTime(current.pending_since);
var dur2 = new GlideDateTime();
dur = GlideDateTime.subtract(dur1, dur2);
var duration = new GlideDuration(dur).getDurationValue(); => I get in HH:MM:SS format
For setting into actual field i.e A OR B OR C I use
tm.setValue('A', dur.getDisplayValue());
Now, I need to add total of them.
But while adding when I get values of three they are already in string format i.e 1 hour 22 minutes, so how can I get value of these fields in terms of HH:MM:SS or any other conversion type? to add total of them
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-09-2020 01:00 AM
Hi,
why not use duration field to store the values?
It would be easier to calculate and sum them up at the end
Anyhow you are calculating the value and storing in string field so use duration field
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-09-2020 01:14 AM