title: exclude weekends in javascript date calculation
body: <p>I have two sets of codes that work. Needed help combining them into one.</p>
  
  <p>This code gets me the difference between two dates. works perfectly:</p>
  
  <pre><code>function test(){
  var date1 = new Date(txtbox_1.value);    
  var date2 = new Date(txtbox_2.value);
  
  var diff = (date2 - date1)/1000;
  var diff = Math.abs(Math.floor(diff));
  
  var days = Math.floor(diff/(24*60*60));
  var leftSec = diff - days * 24*60*60;
  
  var hrs = Math.floor(leftSec/(60*60));
  var leftSec = leftSec - hrs * 60*60;
  
  var min = Math.floor(leftSec/(60));
  var leftSec = leftSec - min * 60;
  
  txtbox_3.value = days + "." + hrs; }
  </code></pre>
  
  <p><a href="https://stackoverflow.com/questions/41948/how-do-i-get-the-difference-between-two-dates-in-javascript">source for the above code</a></p>
  
  <p>The code below by @cyberfly appears to have the answer of excluding sat and sun which is what i needed. <a href="https://stackoverflow.com/questions/3464268/find-day-difference-between-two-dates-excluding-weekend-days">source</a>. However, its in jquery and the above code is in JS. Therefore, needed help combining as i lacked that knowledge :(</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  
  $("#startdate, #enddate").change(function() {       
  
  var d1 = $("#startdate").val();
  var d2 = $("#enddate").val();
  
          var minutes = 1000*60;
          var hours = minutes*60;
          var day = hours*24;
  
          var startdate1 = getDateFromFormat(d1, "d-m-y");
          var enddate1 = getDateFromFormat(d2, "d-m-y");
  
          var days = calcBusinessDays(new Date(startdate1),new Date(enddate1));             
  
  if(days&gt;0)
  { $("#noofdays").val(days);}
  else
  { $("#noofdays").val(0);}
  
  
  });
  
  &lt;/script&gt;
  </code></pre>
  
  <hr>
  
  <p><strong>EDIT</strong>
  Made an attempt at combining the codes. here is my sample. getting <em>object expected error</em>.</p>
  
  <pre><code>function test(){
  var date1 = new Date(startdate.value);    
  var date2 = new Date(enddate.value);
  var diff = (date2 - date1)/1000;
  var diff = Math.abs(Math.floor(diff)); 
  var days = Math.floor(diff/(24*60*60));
  var leftSec = diff - days * 24*60*60;
  var hrs = Math.floor(leftSec/(60*60));
  var leftSec = leftSec - hrs * 60*60;
  var min = Math.floor(leftSec/(60));
  var leftSec = leftSec - min * 60;
  
  var startdate1 = getDateFromFormat(startdate, "dd/mm/yyyy hh:mm");
  var enddate1 = getDateFromFormat(enddate, "dd/mm/yyyy hh:mm");
  days = calcBusinessDays(new Date(startdate1),new Date(enddate1));           
  noofdays.value = days + "." + hrs; }
  
  start: &lt;input type="text" id="startdate" name="startdate" value="02/03/2015 00:00"&gt;
  end: &lt;input type="text" id="enddate" name="enddate" value="02/03/2015 00:01"&gt;
  &lt;input type="text" id="noofdays" name="noofdays" value=""&gt;
  </code></pre>
  
  <p></p>