Skip to main content

Nintex form business days calculator

 function doCalc()

{

  var myDate = NWF$(‘.cssDateChosen’).find(‘input’);

  var dFuture = new Date(“December 31, 2015”);

  dFuture = new Date(myDate.val());

  var dNow = new Date();

  var result = calcBusinessDays(getDateOnly(dNow),getDateOnly(dFuture));

  alert(‘Num of Business Day between Future date and now : ‘ + result + ‘ days’);

}

function dateBusinessDayValidation(source, arguments)

{

  arguments.IsValid=true;

  var myDate = NWF$(‘.cssDateChosen’).find(‘input’);

  var dFuture = new Date(myDate.val());

  var dNow = new Date();

  var result = calcBusinessDays(getDateOnly(dNow),getDateOnly(dFuture));

  if(result < 30)

  {

       arguments.IsValid = false;

  }

}

function calcBusinessDays(dDate1, dDate2)

{

 // input given as Date objects

 var iWeeks, iDateDiff, iAdjust = 0;

 if (dDate2 < dDate1)

  return -1; // error code if dates transposed

 var iWeekday1 = dDate1.getDay(); // day of week

 var iWeekday2 = dDate2.getDay(); iWeekday1 = (iWeekday1 == 0) ? 7 : iWeekday1; // change Sunday from 0 to 7

 iWeekday2 = (iWeekday2 == 0) ? 7 : iWeekday2;

 if ((iWeekday1 > 5) && (iWeekday2 > 5))

   iAdjust = 1; // adjustment if both days on weekend

 iWeekday1 = (iWeekday1 > 5) ? 5 : iWeekday1; // only count weekdays

 iWeekday2 = (iWeekday2 > 5) ? 5 : iWeekday2;  // calculate difference in weeks (1000mS * 60sec * 60min * 24hrs * 7 days = 604800000)

 iWeeks = Math.floor((dDate2.getTime() – dDate1.getTime()) / 604800000) ;

 if (iWeekday1 <= iWeekday2)

 {

  iDateDiff = (iWeeks * 5) + (iWeekday2 – iWeekday1);

 }

 else

 {

  iDateDiff = ((iWeeks + 1) * 5) – (iWeekday1 – iWeekday2);

 } 

 iDateDiff -= iAdjust; // take into account both days on weekend

 return (iDateDiff + 1); // add 1 because dates are inclusive

}

function getDateOnly(myDate)

{

  var dd = myDate.getDate();

  var mm = myDate.getMonth()+1;

  //January is 0!

  var yyyy = myDate.getFullYear();

  if(dd<10)

  {

       dd=’0’+dd;

  }

 if(mm<10)

 {

   mm=’0’+mm;

 }

  var newDateOnly = mm+’/’+dd+’/’+yyyy;

  return new Date(newDateOnly);

}

Comments

Popular posts from this blog

Get Sum of Columns in a SharePoint list (Threshold edition)

It is a known fact that once the treshold limit is reached in SP, everything seems frozen.  At this point you have some options. Increase the limit using powershell or from the Central Admin OR Index the columns that you will like to operate on and create views based on those. However programmatically if you want to sum a list that has reached its threshold.  You can do so in batches as hown below:          protected   void  GetSummary( out   long  ideas,  out   long  votes,  out   long  comments,  out   long  transform)         {              long  ideasum = 0;              long columntoSum = 0;              long  commentS...

Add Web Visual Studio templates to SharePoint Project

Would you like to add the web user control to SharePoint 2007 project development.  Then open the project file with notepad and add {349c5851-65df-11da-9384-00065b846f21} to the ProjectTypeGUIDs node.   The necessary change is shown below: < ProjectTypeGuids > {349c5851-65df-11da-9384-00065b846f21};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} </ ProjectTypeGuids >