- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-05-2017 09:00 PM
hi
i want to create a new field where i want to display difference of create and close date once request gets closed.
and i want difference in days and hours.
how can i achieve this.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-05-2017 09:11 PM
Please use the datediff function to calculate the difference between the date with boolean value as false.
dateDiff(String, String, boolean):
- boolean bnumericValue - true to return difference in number of seconds as a string, false to return difference in the format ddd hh:mm:ss.
GlideSystem Date and Time Functions - ServiceNow Wiki
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-05-2017 09:12 PM
You can use the column "Resolve time" (calendar_stc) on sc_request table. That already captures the time taken for request to get resolved / closed.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-05-2017 09:17 PM
Hi Anshul,
You have to use Date and Time functions to achieve this.
You can refer below links as well:
Find difference between two dates
Using Date and Time Fields - ServiceNow Wiki
Client script:
function onChange(control, oldValue, newValue, isLoading) {
var strt = g_form.getValue('<start_field>');//set this as create date
var end = g_form.getValue('<end_field>');//set this as close date
var ajax = new GlideAjax('AjaxDurCalc');
ajax.addParam('sysparm_name','durCalc');
ajax.addParam('sysparm_strt',strt);
ajax.addParam('sysparm_end',end);
ajax.getXMLWait();
var answer = ajax.getAnswer();
g_form.setValue('<duration_field>', answer);
}
Script include
Name:AjaxDurCalc
Client callable:checked,client:checked
script:
var AjaxDurCalc = Class.create();
AjaxDurCalc.prototype = Object.extendsObject(AbstractAjaxProcessor, {
durCalc: function() {
return gs.dateDiff(this.getParameter('sysparm_strt'),this.getParameter('sysparm_end'), false);
}
});
Please mark Correct/Helpful as per impact of the response!!
Thanks,
Anjali