JavaScript Code


Count the number of working days in a month

function numberOfWorkingDays(month, year) { 
  let counter = 0;
  let date = new Date(year, month - 1, 1);
  const endDate = new Date(date.getFullYear(), date.getMonth() + 1, 0);

  while (date.getTime() < endDate.getTime()) {
    const weekDay = date.getDay();
    if (weekDay !== 0 && weekDay !== 6) {
      counter += 1;
    }
    date = new Date(date.getFullYear(), date.getMonth(), date.getDate() + 1);
  }
  return counter;
}

Calculate the number of days between two dates

function numberOfDays(start, end) { 
  const startDate = new Date(start);
  const endDate = new Date(end);
  return Math.abs((startDate.getTime() - endDate.getTime()) / (1000 * 60 * 60 * 24));
}


© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited TopPrevNext