Hi gus, with help of business days you easily find number days between two dates. But x-pages doesn’t support business day. So this is useful by the following java script and @formulas coding:
Step 1: Get the starting and ending date.
Step 2: Find total number of days between this two days
Step 3: Divide the result value in step2 by 7 and then multiply this value by 2
Step :4 Subtract this value from total days
Coding:
var sd=getComponent(”StartDate”).getValue(); // Starting date
var ed=getComponent(”EndDate”).getValue(); //Ending date
var weekdays=0;
var days=@Day(ed)-@Day(sd);
if(@Month(sd)==”1.0″ || @Month(sd)==”3.0″ ||@Month(sd)==”5.0″ ||@Month(sd)==”7.0″ ||@Month(sd)==”8.0″ ||@Month(sd)==”10.0″ ||@Month(sd)==”12.0″)
//To find number days between two give dates
var months=(@Month(ed)-@Month(sd))*31;
if(@Month(sd)==”4.0″ || @Month(sd)==”6.0″ ||@Month(sd)==”9.0″ ||@Month(sd)==”11.0″)
var months=(@Month(ed)-@Month(sd))*30;
if(@Month(sd)==”2.0″)
var months=@Month(sd)*28;
if(@Year(sd)%4==0) //If the give is year is leaf year
var years=(@Year(ed)-@Year(sd))*366;
else //Ordinary Year
var years=(@Year(ed)-@Year(sd))*365;
var tdays=days+months+years+1; //Total days
if(tdays>=7)
weekdays=Math.floor(tdays/7); //Calculate number of weeks
var ds=tdays-(weekdays*2); //number of days excluding Week start and end dates
getComponent(”Duration”).setValue(ds);
No comments:
Post a Comment