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 remove time part

Chirag10
Mega Contributor

Hi All,

I have written a below scheduled script which is capturing days in three figure.

update_days();

function update_days() {
var gr = new GlideRecord("sc_req_item");
gr.addQuery('Active', true);
gr.query();
while (gr.next()) {
var datediff = gs.dateDiff(gs.nowDateTime(), gr.u_resolved.getDisplayValue(), false);
var days = datediff.split("");
//var days = datediff;
gr.u_duration = days[0] + days[1] + days[2];
gr.update();
}
}

 

But when I check the count of days remaining from Now to close date, it is showing it is fetching the time also..

find_real_file.png

according to <gr.u_duration = days[0] + days[1] + days[2];> I am getting this time value that is 2 after number of days. Is there any Possibility to remove the time from the above duration field. 

1 ACCEPTED SOLUTION

Replace var days = datediff.split(""); with var days = datediff.split(" "); , to split on the bases of space.

Then use gr.u_duration = days[0]; as it will contain actual number of days irrespective of number of figures.

View solution in original post

5 REPLIES 5

Thanks Muhammad.