- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2023 02:09 AM
Hello all,
I have written a business rule for one case, in that script I have written the following logic but it was not working. The following is the scenario-
there are two fields in utc_start_time and utc_end_time. I want the difference between the start time and endtime in numeric value(minutes). because I need to multiply with some value after this logic. Can anyone helpme on this.
//utc_start and utc_end time are date/time field
var start_time = new GlideDuration(current.utc_start_time);
var end_time = new GlideDuration(current.utc_end_time);
var currentTime = new GlideDateTime();
var current_time = new GlideDuration(currentTime);
var myDuration;
if (current.u_utc_end_time != "") {
myDuration = end_time.subtract(start_time);
}
} else {
myDuration = current_time.subtract(start_time);
}
var minutes = myDuration.getNumericValue();
var res1 = minutes * current.count;
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2023 02:50 AM
Hi,
Here is an example to get the difference in minutes on two DateTime objects.
var startDate = new GlideDateTime(current.getValue('your_start_time_field'));
var endDate = new GlideDateTime(current.getValue('your_end_time_field'));
var differenceMS = endDate.getNumericValue() - startDate.getNumericValue();
var diffMinutes = differenceMS / (60 * 1000);
gs.info('diff Min: ' + diffMinutes);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2023 04:00 AM
thank you very much