spacer
Yehuda Shiran February 20, 2001
Computing the Next Business Day
Tips: February 2001

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs

In many applications you need to find the next business day. Suppose you operate a purchasing and delivering site on the Web. Your operation model constrains your delivery service to send out every package the next business day. You probably want to tell your customers at which date the package would leave the premises. A bank processes customer applications for a new account in one business day. The bank would like to inform applicants when should they check back about their applications. These are typical examples where computing the next business day is very handy. The following function, getNextBusinessDay(), computes the next business day. We take advantage of our function, getDeliveryDateObj(1), which forward-computes the date, counting business days only. We just pass the value of 1 to this function (national holidays are counted as business days):

<SCRIPT LANGUAGE="JavaScript">
function getNextBusinessDay() {
  return getDeliveryDateObj(1);
}

function getDeliveryDateObj(businessDaysLeftForDelivery) {
  var now = new Date();
  var dayOfTheWeek = now.getDay();
  var calendarDays = businessDaysLeftForDelivery;
  var deliveryDay = dayOfTheWeek + businessDaysLeftForDelivery;
  if (deliveryDay >= 6) {
    businessDaysLeftForDelivery -= 6 - dayOfTheWeek;  //deduct this-week days
	calendarDays += 2;  //count this coming weekend
	deliveryWeeks = Math.floor(businessDaysLeftForDelivery / 5); //how many whole weeks?
	calendarDays += deliveryWeeks * 2;  //two days per weekend per week
  }
  now.setTime(now.getTime() + calendarDays * 24 * 60 * 60 * 1000);
  return now;
}
</SCRIPT>

Click here to find out the next business day.


People who read this tip also read these tips:

Look for similar tips by subject:

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Building a Banking Application Home Page with OOP · Mixing Scripting Languages · Review: phpFox, a Social Networking CMS with all the Bells and Whistles
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Enterprise 2.0: Social Networking in the Cloud · BroadSoft Marketplace Hastens Pace of Telephony Innovation · Review: HTC Hero for Sprint