Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

[AEM Gems Webinar] Accelerating Experience Manager as a Cloud Service development with Rapid Development Environments

Calculate the number of week days between two dates considering Friday and Saturday as weekends


Level 1

How can I calculate the number of week days between two dates considering Friday and Saturday as weekends.

Thanks & Regards


0 Replies


Level 10

Hi Shyam,

Using JavaScript you could use the following function, which loops though from the start date to the end date and uses the standard getDay function to determine which day of the week we are dealing with.

function CalculateBusinessDays(startDate, endDate, weekend)


  var result = 0;

  for (var currentDate = startDate; currentDate.getTime() < endDate.getTime(); currentDate.setDate(currentDate.getDate()+1))


    if (weekend.indexOf(currentDate.getDay()) < 0)





  return result;


If you have two DateTimeFields then you can call this function using the following code

var startDate = util.scand("yyyy-mm-dd", StartDate.rawValue);

startDate = new Date(startDate.setHours(0,0,0,0)); // ensure we are are not dealing with any time values.

var endDate = util.scand("yyyy-mm-dd", FinishDate.rawValue);

endDate = new Date(endDate.setHours(0,0,0,0));

var Days = { Sunday : 0, Monday : 1, Tuesday : 2, Wednesday : 3, Thursday : 4, Friday : 5, Saturday : 6 };

BusinessDays.rawValue = CalculateBusinessDays(startDate, endDate, [Days.Friday, Days.Saturday]);