- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2022 01:43 PM
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();
}
Thanks,
Solved! Go to Solution.
- Labels:
-
Incident Management

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2022 04:21 PM
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.***
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2022 08:18 AM
Its working now. Thank you

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2022 08:22 AM
Good. No problem
***Mark Correct or Helpful if it helps.***
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2022 10:09 PM
Hi @reddy8055 ,
Try below code, it should work for you:
var gr = new GlideRecord('incident');
gr.query();
while (gr.next()) {
var dat = new GlideDateTime();
var datedif =gs.dateDiff(gr.getDisplayValue('sys_created_on'), dat, true) ; // Returns difference in second
datedif = Number(datedif) // Convert this to number
var days = datedif /86400 //Convert seconds to days
gr.u_total_days = datedif;
gr.update();
}
I Hope this helps.
Please mark this helpful if this helps and Accept the solution if this solves your issue.
Regards,
Kamlesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2022 08:04 AM
Hi,
where did you define number on line 6?
I am getting like below
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2024 01:47 PM
@reddy8055 Where do you add this script? Client Script? Scheduled job?