- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2022 12:33 AM
How to get Due Date and Current Date Difference using BR? I have a scenario where I have a need to get Difference of current date and due date and need to publish via report. I need to show difference in days only. Should I use client script instead of BR?
I tried this :
var date=new GlideDate();
var current=date;
gs.info(current) //Showing me the current Date
var gr=new GlideRecord('table_name');
var dd=gr.getValue('due_date'); or var dd=gr.getDisplayValue('due_date');
var diff=dd-current;
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-23-2022 05:07 AM
Hi
this script will work in scoped app and give the difference in days
Note: If you wish to populate the difference in some field when BR runs; the BR should be Before and not After
var currentTime = new GlideDateTime();
var actualDatetime = new GlideDateTime(current.due_date);
var dur = new GlideDuration();
dur = GlideDateTime.subtract(currentTime, actualDatetime);
var days = dur.getDayPart();
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2022 12:45 AM
Hi
Refer to this thread: https://community.servicenow.com/community?id=community_question&sys_id=63108f21db98dbc01dcaf3231f96...
Mark my answer correct & Helpful, if Applicable.
Thanks,
Sandeep
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-27-2022 08:17 PM
Hi
Any update to this ?Any follow-up required? if not
Kindly mark the answer as Correct & Helpful both such that others can get help.
Thanks,
Sandeep
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2022 01:04 AM
Hi Vishal,
Please try below script:
var gr=new GlideRecord('table_name');
var diff = gs.dateDiff(gs.nowDateTime(), gr.due_date.getDisplayValue(), true);
gs.print(diff/(60*60*24))
Feel free to mark correct, If I answered your query.
Will be helpful for future visitors looking for similar questions 🙂
Regards,
Shekhar
Regards, Shekhar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-23-2022 04:37 AM
Hi Shekhar,
I tried this dateDiff() in my BR, But it says not supported in this scope.
Thanks & Regards,
Vishal Kumar Srivastava