Expand my Community achievements bar.

Add variable number of weekdays to date field

Avatar

Level 2

When my user selects a "target start date" for a contract task, I want to add the number of "allowable days" to that date. (That value comes from a text field populated with a number, which varies based on a dropdown menu listing the types of contracts they can work on.) This calculated date should appear in a "target completion date" field. Where I'm getting stuck is that the "allowable days" for the task must only be counting business days (Monday-Friday).

Here are the names of my fields:

Allow.Row1.Cell   //  text field that will populate with a specific number of days based on a dropdown menu selection.

Dates.Row1.TARGETSTART   //   date field

Dates.Row1.TARGETEND   //   date field

This is the code I had that works but does include weekends. I want to exclude weekends.

if(HasValue(Dates.Row1.TARGETSTART)) then

Num2Date( (Date2Num(Dates.Row1.TARGETSTART.formattedValue, "MM-DD-YYYY") + Allow.Row1.Cell), "MM-DD-YYYY") + 1

I searched through the discussion boards and can't find anything that I've been able to edit properly to fit my situation! Any help would be greatly appreciated.

2 Replies

Avatar

Level 8

Add to your condition:

if (HasValue(Dates.Row1.TARGETSTART)) and

Num2Date(Date2Num(Dates.Row1.TARGETSTART.formattedValue, "MM-DD-YYYY") EEEE")<>"Saturday" and

Num2Date(Date2Num(Dates.Row1.TARGETSTART.formattedValue, "MM-DD-YYYY")  EEEE")<>"Sunday") then

.

.

.

Kyle

Avatar

Level 2

Thank you, but it's not recognizing the "and" after "Saturday" and the "then" after "Sunday". I tried removing the end quotation mark after EEEE or adding an opening quotation mark before EEEE but nothing is making that code work:

if (HasValue(Dates.Row1.TARGETSTART)) and

Num2Date(Date2Num(Dates.Row1.TARGETSTART.formattedValue, "MM-DD-YYYY") EEEE")<>"Saturday" and

Num2Date(Date2Num(Dates.Row1.TARGETSTART.formattedValue, "MM-DD-YYYY")  EEEE")<>"Sunday") then

(Dates.Row1.TARGETSTART.formattedValue

, "MM-DD-YYYY") + Allow.Row1.Cell), "MM-DD-YYYY") + 1

I am putting this in the TARGETEND date field as a calculation using FormCalc.