Adobe LiveCycle FormCalc Example – Calculating Business Days

Recently I taught an Adobe Livecycle forms course where one of the students asked me to cobble together some FormCalc code that would calculate X business days from a user-entered date.

This was the result:

var startdate = Date2Num($,"YYYY-MM-DD");
var bizdays = 10;
var modifier = 0;

// figure out modifier
for i=1 upto bizdays step 1 do
 var day = Date2Num($,"YYYY-MM-DD") + i;
 var dayOfWeek = Num2Date(day,"EEE");
 if (dayOfWeek == "Sat" or dayOfWeek == "Sun") then
   modifier = modifier + 1;
 endif
endfor

var enddate =  Date2Num($,"YYYY-MM-DD") +  bizdays + modifier;

Date2 = Num2Date(enddate,"YYYY-MM-DD");

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s