Avatar

Level 2

Hi, It's not working yet, I have three fillable fields named as:

"Date field"

"Days"

"Calculate Date"



1. I want that that i can enter date in "startDate" with this format: dd mmm yyyy

2. Then i enter numbers of days  in "days" fields

3. I want the result in "Calculate Date" field but i want that script count 5 days in a week. (Skip all weekend days like Saturday and Sunday)


Please see below as sample


Sunday 6 Mar 2016 + 20 days = Monday 4 Apr 2016  (Skip all weekend days)


Please, see below script, but there is problem that this script not skip weekend days:


// Custom Calculate script for NewDate field

(function () {

    // Get date entered into the OrigianlDate field

    var sDate = getField("OriginalDate2").valueAsString;

    // Convert string to date

    var d = util.scand("dddd d mmm yyyy", sDate);

    // Get the number of days added, as a number

    var days = getField("DaysAdded10").value;

    // Add days to date

    d.setDate(d.getDate() + days);

    // Populate this field with the result

    if (sDate) {

        event.value = util.printd("dddd d mmm yyyy", d);

    } else {

        event.value = "";

    }

})();

Please amend this code, so that week should count 5 days in a week or skill all Saturday and Sunday