I am trying to fetch the date from present date to past date of 3 business days,i am using below script but it fetches the future date..Can any one suggest me which script i need to use for past days of business days?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-21-2022 11:16 AM
var startDate = new GlideDateTime();
var days = 3;
var dur = new GlideDuration(60 * 60 * 24 * 1000 * days);
var schedule = new GlideSchedule('090eecae0a0a0b260077e1dfa71da828');
var end = schedule.add(startDate, dur);
gs.print(startDate);
gs.print(end);
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-21-2022 11:30 AM
Check below thread, if it helps
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-22-2022 12:39 AM
Thank you, Sanjiv for sharing the thread.
I looked into your post and I created a script include class as he provided in the post but is I'm not able to fetch the past date of business days, It's fetching the normal days only.
Any suggestions from your side
Thanks in advance
Chaitanya.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-22-2022 10:25 AM
So you new script should be
var startDate = new GlideDateTime();
var su = new ScheduleUtils();
varend = su.subDaysInSchedule("<Name of the schedule>",startDate, 3);
gs.info(startDate);
gs.info(end);
Can you post your script it is different from above?
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-22-2022 12:44 AM
Hi Chaitanya,
Please try below script,
var startDate = new GlideDateTime();
var days = -3;//we need to use here -3 as you need past records
var dur = new GlideDuration(60 * 60 * 24 * 1000 * days);
var schedule = new GlideSchedule('090eecae0a0a0b260077e1dfa71da828');
var end = schedule.add(startDate, dur);
gs.print(startDate);
gs.print(end);
Let me know if you have any further queries.
Please mark this as Correct or Helpful if it helps.
Thanks and Regards,
Abhijit
Community Rising Star 2022
Regards,
Abhijit
ServiceNow MVP