Last week as part of the training program, I was overseeing the XPages project done by the new recruits. They had to create a functionality to get input time-in and time-out data of all employees from the Magnetic Swipe Card system to calculate the time an employee spent in the Office. After that, they had to send alert mails to whoever had not put in the requisite hours for the week. This functionality involved, among other things, the calculation of business days between two given dates. While this functionality is in-built in Formula language, the freshers found it difficult to get this working in XPages. To help them out, I had written the code which I have given below.
This code expects, a StartDate, an endDate, daysToExclude (weekly off) and datesToExclude (specific holidays) and returns the number of business days.

For example Sunday is taken as one , Saturday as 7 and the Public Holidays are as given below. These days are passed to the function and are all skipped to get at the actual business days between a StartDate and an EndDate.

function businessDays(startDate, endDate,daysToExclude,datesToExclude ){


var sDate:NotesDateTime=session.createDateTime(startDate) //getting start date

var eDate:NotesDateTime=session.createDateTime(endDate)

//getting enddate

var pubarray=new Array();

var daystoexclude = @Explode(daysToExclude,”;”);

//calculating the week days


var hday=@Explode(datesToExclude,”;”)

var hdayarray=new Array();







var temp:NotesDateTime=session.createDateTime(hday[i])




var pubdays=@Implode(hdayarray,”:”)

//Calculating the public holidays

var sDatesquare=”[“+sDate.getDateOnly()+”]”

var eDatesquare=”[“+eDate.getDateOnly()+”]”

var formula=””


formula=”@BusinessDays( “+sDatesquare+”;”+eDatesquare+”;”+daystoexclude+”)”



formula=”@BusinessDays( “+sDatesquare+”;”+eDatesquare+”;”+daystoexclude+”;”+pubdays+”)”


var duration=session.evaluate(formula);

return duration



return e.message



log.logError(e.message, severity, ”, ”, view.getPageName(), functionName);



This function works out to be very handy and we have even used this for our payroll system. Try it out if you have a similar problem and I like to hear your feedback on the code.

About the author

Krishnamoorthy is a Software Engineer from Maarga Systems who works extensively on Lotus Domino and loves to watch short films from around the world and plays chess.