The CreatorCon Call for Content is officially open! Get started here.

How can I get number of days ticket has been opened

reddy8055
Tera Contributor

Hi,

I have created a string field on incident and trying to get total days of incident opened based on created date and todays date. Its showing time as well, how can I remove time and show only days.

 

 

var gr = new GlideRecord('incident');
gr.query();
while (gr.next()) {
    var dat = new GlideDateTime();
    var datedif = gs.dateDiff(gr.sys_created_on, dat);
    gr.u_total_days = datedif;
    gr.update();

}

 

 

reddy8055_0-1666989788688.png

Thanks,

  

1 ACCEPTED SOLUTION

Yousaf
Giga Sage

Hi reddy,
Try this please

var gr = new GlideRecord('incident');
gr.query();
while (gr.next()) {
    var dat = new GlideDateTime();
    var datedif = gs.dateDiff(gr.sys_created_on, dat);
    gr.u_total_days = datedif.split(' ')[0];
    gr.update();

}


Mark Correct and Helpful if it helps.


***Mark Correct or Helpful if it helps.***

View solution in original post

9 REPLIES 9

Yousaf
Giga Sage

Hi reddy,
Try this please

var gr = new GlideRecord('incident');
gr.query();
while (gr.next()) {
    var dat = new GlideDateTime();
    var datedif = gs.dateDiff(gr.sys_created_on, dat);
    gr.u_total_days = datedif.split(' ')[0];
    gr.update();

}


Mark Correct and Helpful if it helps.


***Mark Correct or Helpful if it helps.***

reddy8055
Tera Contributor

Hi,

I tried this, its not working.

 

Did you copy/pasted the code I shared above you probably missed the space in split(' '). otherwise it should work was working on my PDI


***Mark Correct or Helpful if it helps.***

Yousaf_1-1667229555874.png

 

 


***Mark Correct or Helpful if it helps.***