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

Chirag10
Mega Contributor

@Ankur Bawiskar  can you please help on this.

Muhammad Khan
Mega Sage
Mega Sage

Hi Chirag,

 

Replace gr.u_duration = days[0] + days[1] + days[2]; with gr.u_duration = days[0];

 

Hopefully this will resolve your problem.

Hi ,

 

It will not resolve my problem as days[0] only return the first figure of the number.

 

Like for example, no. of days is 18, then days[0] will return 1. If it take days[0] + days[1], it will return 18. May be in future, requirement will be in three figures so i have taken days[0]+days[1]+days[2]. 

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.