- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2022 11:04 PM
Hello,
I am trying to calculate the next date based on the scheduled selected.
For example:
Date I have is of today and schedule I am using is repeat every 2nd Saturday at 2 pm
How can I calculate the date of that Saturday based on the today's date.
Thanks in advance!
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2022 11:53 PM
Hi Sudeep,
I would create a schedule that'll repeat on Saturday and then add date to that schedule to get the next date.
e.g.
Schedule. I've set the scheduled time to be 1 hour from 14:00 to 15:00.
Script
var startDate = new GlideDateTime();
startDate.setDisplayValue('2022-04-02 14:00:00');
var days = 1;
var dur = new GlideDuration(60 * 60 * 1 * 1000 * days);
var sched = new GlideSchedule('2896217597fa011086d3b4b3f153af7d');
var end = sched.add(startDate, dur);
gs.info(end.getDisplayValue());

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2022 11:53 PM
Hi Sudeep,
I would create a schedule that'll repeat on Saturday and then add date to that schedule to get the next date.
e.g.
Schedule. I've set the scheduled time to be 1 hour from 14:00 to 15:00.
Script
var startDate = new GlideDateTime();
startDate.setDisplayValue('2022-04-02 14:00:00');
var days = 1;
var dur = new GlideDuration(60 * 60 * 1 * 1000 * days);
var sched = new GlideSchedule('2896217597fa011086d3b4b3f153af7d');
var end = sched.add(startDate, dur);
gs.info(end.getDisplayValue());

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2022 11:57 PM
My bad. It was to calculate the next date based on today. I've used Schedule in case it's necessary to consider holidays.
Comment out the startDate.setDisplayValue().
var startDate = new GlideDateTime();
var days = 1;
var dur = new GlideDuration(60 * 60 * 1 * 1000 * days);
var sched = new GlideSchedule('2896217597fa011086d3b4b3f153af7d'); // sys_id of "Every Saturday at 2pm" schedule
var end = sched.add(startDate, dur);
gs.info(end.getDisplayValue());
Execution result:
*** Script: 2022-04-16 14:00:00
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2022 07:40 AM
Hi,
Can I create a business rule for this schedule?