In this example we calculate a date, based on an input date in a date control. Within the below rule, we add days based on the selected date. For example, if its Monday, we add 3 days, if it's Thursday, we add 4 days, etc. You can use this rule for assisting with date calculations. This rule also logs items to the Javascript Console as it runs for more informational purposes using output.log().
JavaScript
// d should be whatever your date field is, otherwise leave it alone, ie: date.datefiled
var d = data.startingDate;
// Gets the Current Day of the Week from the starting Date field.
var day = d.getDay();
var actualDay;
var newDay = new Date();
if (day === 0)
{ actualDay = 'Sunday';}
else if (day == 1)
{ actualDay = 'Monday';}
else if (day == 2)
{ actualDay = 'Tuesday';}
else if (day == 3)
{ actualDay = 'Wednesday';}
else if (day == 4)
{ actualDay = 'Thursday';}
else if (day == 5)
{ actualDay = 'Friday';}
else if (day == 6)
{ actualDay = 'Saturday';}
// Here we echo the resulting day integer to console and the day of week
console.log('Today is: ' + day);
console.log('Today is: ' + actualDay);
// Here we evaluate the day and perform math to calculate the day.
if (actualDay == 'Sunday')
{
// The +1 here adds 1 business day. You can change the 1 to any integer to suite your calculations.
newDay.setDate(d.getDate() + 1);
console.log('Calculated Day is: ' + newDay);
}
// the + 3 here adds 3 days to the input date
if (actualDay == 'Monday')
{
newDay.setDate(d.getDate() + 3);
console.log('Calculated Day is: ' + newDay);
}
if (actualDay == 'Tuesday')
{
// the + 3 here adds 3 days to the input date
newDay.setDate(d.getDate() + 3);
console.log('Calculated Day is: ' + newDay);
}
if (actualDay == 'Wednesday')
{
// the + 3 here adds 5 days to the input date
newDay.setDate(d.getDate() + 5);
console.log('Calculated Day is: ' + newDay);
}
// the + 4 here adds 4 days to the input date
if (actualDay == 'Thursday')
{
// the + 3 here adds 4 days to the input date
newDay.setDate(d.getDate() + 4);
console.log('Calculated Day is: ' + newDay);
}
// the + 3 here adds 3 days to the input date
if (actualDay == 'Friday')
{
newDay.setDate(d.getDate() + 3);
console.log('Calculated Day is: ' + newDay);
}
// the + 2 here adds 2 days to the input date
if (actualDay == 'Saturday')
{
newDay.setDate(d.getDate() + 2);
console.log('Calculated Day is: ' + newDay);
}
var v = newDay;
// Write the Formated Date into a text field.
value = v.getMonth()+1 + '/' + v.getDate() + '/' + v.getFullYear();
Attached to this form post is an example form.