Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to find the difference between current date and due date in ServiceNow

Arun91
Tera Contributor

Hi All,

 

I have to find the difference between current date and due date in Issue Management module. Based on the due date i have to update the status in issue management. I need to get the due date in Days. Based on the days i have to update the status. Please help me. Here it is my code.

var abc = new GlideRecord("sn_grc_issue");
abc.addEncodedQuery("sys_idSTARTSWITHbb5179b21bb0391024f7531b234bcbb1")
//5bf43db71b27751024f7531b234bcb2c");
abc.query();
if (abc.next()){
   var now = new GlideDateTime();
   var xyz = new GlideDateTime(current.due_date);
  // xyz = abc.getValue("due_date");
    var dte = GlideDateTime.subtract(xyz,now);
    var diff = (dte.dateNumericValue())/86400000;
gs.info('hai' + now);
gs.info('hai22' + dte);
gs.info('arun' + diff);
gs.info(diff);
 if(xyz < now){
abc.u_timeline_status = 'past_due';
abc.update();
}else if(diff <= 30 ){
abc.u_timeline_status = 'coming_due';
abc.update();
 }else if(diff > 31){
abc.u_timeline_status = 'in_progress';
abc.update();
}



 }
2 REPLIES 2

Anurag Tripathi
Mega Patron
Mega Patron

Check this Arun, similar question is answered here.

Solved: Calculate the amount of days between two dates - ServiceNow Community

-Anurag

chetanb
Tera Guru

@Arun91 

 

you can update your code for date difference logic as

 

if my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.

 

Regards,

CB

 

 

var now = new GlideDateTime();
var xyz = new GlideDateTime(current.due_date);
// xyz = abc.getValue("due_date");
//In Millisec
var dte = GlideDateTime.subtract(now,xyz).getNumericValue();
//in days
var dtdays=dte/(1000*6060*24);