How to add 5 days to a date excluding weekends

Hari1
Mega Sage

Hi,

I have a date, I need to add 5 days to it which should exclude weekends. I am using this code on a scheduled job code block.

var triggerFirstNotification = "24/05/2022";

var addDaysFive = new GlideDateTime(triggerFirstNotification);
addDaysFive.addDaysUTC(5);

var days = 0;

if (addDaysFive.getDayOfWeekUTC() != 6 && addDaysFive.getDayOfWeekUTC() != 7) {
    days++;
}

I should get the output as 30/05/2022. Which should include the current date as well in its count.

 

3 REPLIES 3

dmathur09
Kilo Sage
Kilo Sage

Hi Hari,

Refer the similar community article with an accepted response - https://community.servicenow.com/community?id=community_question&sys_id=40ef47a5dbdcdbc01dcaf3231f961947

Regards,

Deepankar Mathur

Community Alums
Not applicable

Hi Hari,

Here is a correct answer mentioned just replace 3 days with 5 days:

https://community.servicenow.com/community?id=community_question&sys_id=20e32d45dbc99c1014d6fb243996...

Mark my answer correct & Helpful, if Applicable.

Thanks,
Sandeep

 

The answer in the post doesn't meet the requirement that i am look for. I have a date and i need to add 5 days to it which should exclude weekends.