Calculate Date in Business Days
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2022 01:38 PM
Hello Community,
How can I calculate a target date counting business days only?
Example : User enters start date on catalog item date field - 1/24/2022
Goal : The script should calculate 10 days from the start date considering *business days only* and should populate the end date field with 2/7/2022
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2022 01:44 PM
Hello
Please use the below
var startDate = new GlideDateTime(current.start_date);
var days = parseInt(current.no_ofdays); //assuming there are 8 business hours
days = days*8;
var dur = new GlideDuration(60 * 60 * 1000 * days);
var schedule = new GlideSchedule('472acc8d1b521c1012c0dc6cdc4bcbb2'); //put your schedule sys_id here
var end = schedule.add(startDate, dur);
current.end_date=end;
Please mark answer correct/helpful based on impact
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2022 02:13 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2022 02:25 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2022 02:30 PM
var input = "01-24-2022";
var number = 10;
var startDate = new GlideDateTime(input);
gs.print(startDate);
var days = parseInt(number); //assuming there are 8 business hours
days = days*8;
var dur = new GlideDuration(60 * 60 * 1000 * days);
var schedule = new GlideSchedule(gs.getProperty('cmn_schedule.business_days')); //put your schedule sys_id here
var end = schedule.add(startDate, dur);
gs.print(end);