- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2017 08:55 AM
I want a field to display the difference between two times in minutes.
Eg: Business Duration = 136
Solved! Go to Solution.
- Labels:
-
Incident Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2017 11:00 AM
Hello Santhana
Please try below. g_form doesnot work server side
(function calculatedFieldValue(current) {
var dateString1 = new GlideDateTime(current.begin); //make sure variable name is begin
var dateString2 = new GlideDateTime(current.end); // make sure variable name is end
var diffSeconds = gs.dateDiff(dateString1, dateString2, true);
diffMins = diffSeconds/60;
return Math.round(diffMins); // return the calculated value
})(current);
Please mark my response as correct and helpful if it helped solved your question.
-Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2017 10:57 AM
The rule didnt work. The type of the Business Duration field is an integer. Is that a problem?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-24-2025 01:07 AM
To calculate the time difference between two Date/Time fields in minutes, use a GlideDateTime difference and convert it to minutes:
var gdtStart = new GlideDateTime(current.begin);
var gdtEnd = new GlideDateTime(current.end);
// Difference in milliseconds
var diff = gdtEnd.getNumericValue() - gdtStart.getNumericValue();
// Convert ms → minutes
var minutes = diff / 1000 / 60;
current.u_business_duration = minutes;
Begin: 2017-12-26 07:39:52
End: 2017-12-26 09:55:52
Difference: 2 hours 16 minutes = 136 minutes
