Client Script:
function onChange(control, oldValue, newValue, isLoading) { var strt = g_form.getValue("start_date"); var end = g_form.getValue(end_date); var ajax = new GlideAjax('DateCalculattion'); ajax.addParam('sysparm_name','dateCal'); ajax.addParam('sysparm_strt',strt); ajax.addParam('sysparm_end',end); ajax.getXMLAnswer(getDateDiff); } function getDateDiff(answer) { g_form.setValue("date_diff", answer); }
Name:DateCalculattion
Client callable:checked,client:checked
var DateCalculattion = Class.create(); DateCalculattion.prototype = Object.extendsObject(AbstractAjaxProcessor, { dateCal: function() { return gs.dateDiff(this.getParameter('sysparm_strt'),this.getParameter('sysparm_end'), false); } });
How to find difference between two dates in ServiceNow?
Working Code Edited question August 22, 2023