dynamicreport.com News Member Login Knowledge Base Site Map
Support Support Ticket Contact Us
Products Drag & Drop Objects Drag & Drop Calendar UNIGEN Web Reporting Code View
Testimonials Downloads
Order

Knowledge Base Print printer-friendly page.

Login

UNIGEN

ddobj

News



Article #1015: Count Business Days Between Date Ranges

 

Often times it is necessary to determine the number of days that have elapsed between a start and an end date range. An additional array could be read for additional holidays during which businesses are closed. However for the purposes of this article only the weekends will be excluded from the count of days in the range of dates. The function below is useful when time-sensitivity accounts for business days only. E.g. The number of business days to process the delivery of an order from the current date to the expected date of delivery.

function get_business_days (date_start, date_end)
{
 var bdays = 0;
 while (date_start <= date_end)
 {
  if (date_start.getDay () != 0 && date_start.getDay () != 6)
   bdays++; // increment business days (exclude weekend)
  date_start.setDate (date_start.getDate () + 1);
 }
 return bdays;
}

Code View - dynamicreport.com

Obtain the date components from each input textbox and calculate the remaining business days from today to the date provided.

function test_dates ()
{
 var bdays;
 var y = 1 * document.getElementById ("y").value;
 var m = 1 * document.getElementById ("m").value - 1; // 0 = 1st
 var d = 1 * document.getElementById ("d").value;
 var date_today = new Date ();
 var date_target = new Date ();
 date_target.setFullYear (y, m, d);

 bdays = get_business_days (date_today, date_target);
 alert ("A total of " + bdays + " business days will elapse from today.");
}

Code View - dynamicreport.com


yyyy

mm

dd

 

 


Back to article listing

 



 

Copyright © 2007-2008 Interaxis. All rights reserved.
Contact Webmaster