Delta Business Days

[Total: 0    Average: 0/5]

This shows how to take form data and figure out the delta number of days from those dates and also the number of business days delta.

Body Code:

<form name=exf1>
D1 <input name=d1 type=text value="01">
M1 <input name=m1 type=text value="01">
Y1 <input name=y1 type=text value="2000">
<BR>
D2 <input name=d2 type=text value="03">
M2 <input name=m2 type=text value="05">
Y2 <input name=y2 type=text value="2000">
<BR>
Delta Days <input type=text name=delta value="<?>">
<BR>
Business Days <input type=text name=bizdelta value="<?>">
<BR>
<input type=button onclick="compute()" value="compute!">
</form>
<script type=text/javascript>
function compute() {
  var date1 = new Date();
      date1.setYear  (document.exf1.y1.value);
	  date1.setMonth (document.exf1.m1.value);
	  date1.setDate  (document.exf1.d1.value);
  var date2 = new Date();
      date2.setYear  (document.exf1.y2.value);
	  date2.setMonth (document.exf1.m2.value);
	  date2.setDate  (document.exf1.d2.value);
  var delta = date1.getTime() - date2.getTime();
      delta = delta / ( 1000 * 60 * 60 * 24 );  // units are now days.
      if (delta < 0) delta = -delta;
	  delta = Math.round(delta);
	  
  var bizdelta = ((parseInt(delta) / 7) * 5) + (parseInt(delta)%7);
      bizdelta = Math.round(bizdelta);
	  
  document.exf1.delta.value = delta;
  document.exf1.bizdelta.value=bizdelta;
}
</script>

Times Viewed: 10

Leave a Reply

Your email address will not be published. Required fields are marked *