Set a default date as 5 business days opposed to 5 days.

Marc43
Kilo Expert

I currently have a date variable with a default value set for 5 days past the day the request is submitted. However, we would like to set this as 5 business days to not include weekends. Is this possible? Below is the script we are currently using for the default value:

javascript: new GlideDateTime(gs.daysAgo(-5)).getDisplayValue();

1 ACCEPTED SOLUTION

//Try this as the default value

 

javascript: var d5 = '';
var gdt = new GlideDateTime();
var d = 5;
if (gdt.getDayOfWeek() == 6) {
daysout = daysout + 2;
}
if (gdt.getDayOfWeek() == 7) {
d = d + 1;
}
d = d * -1;
d5 = new GlideDateTime(gs.daysAgo(d)).getDisplayValue();
d5;

Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Vinod Kumar Kachineni
Community Rising Star 2022

View solution in original post

5 REPLIES 5

Bill11
Kilo Expert

Honestly at this point why not set it for 7 days? Worst case your 5 days ends on Friday and you have a partial business day while it closes on Sunday.

Unfortunately that is not the route the customers want to go. 

vkachineni
Kilo Sage
Kilo Sage

//Untested code

//try something like

 

var gdt = new GlideDateTime();
var daysout = 5;

//if today is saturday
if(gdt.getDayOfWeek() == 6)
{
daysout = daysout + 2;
}

//if today is sunday
if(gdt.getDayOfWeek() == 7)
{
daysout = daysout + 1;
}

 

//calculate the days out
daysout = daysout *-1;

 var days5out = new GlideDateTime(gs.daysAgo(daysout)).getDisplayValue();


gs.print(days5out);

 

 

 

 

Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Vinod Kumar Kachineni
Community Rising Star 2022

This does not appear to work when I set it as a default value, which is where the date will need to populate.