title: Javascript Adding Time for a Future Date
body: <p>I looked at some other questions, and don't see my specific problem, so please excuse me if it has been asked or answered.</p>
  
  <p>What I am trying to do is figure out a simple "payment" calculator, and provide some additional information, such as the first payment date, and the last.</p>
  
  <p>In some cases, the day of the last payment works, and sometimes it doesn't.</p>
  
  <p>Here's my code:</p>
  
  <pre><code>var myDate = new Date();
  
  var odo = document.contract.firstPaymentDate.value;
  var n = odo.split("/"); 
  var month = n[0];
  var day = n[1];
  var year = n[2];
  
  var oldDateObj = new Date(year, month, day);
  var newDateObj = new Date(oldDateObj.getTime() + ((document.contract.totalNumberRegularPayments.value - 1)*1209600*1000));
  var dd = newDateObj.getDate();
  var mm = newDateObj.getMonth();
  var y = newDateObj.getFullYear();
  
  var someFormattedDate = mm + '/'+ dd + '/'+ y;
  document.contract.lastPaymentDate.value = someFormattedDate;
  </code></pre>
  
  <p>So I take the first payment date, and add 1209600 seconds times the number of payments (minus 1 since they have "already" paid the first).</p>
  
  <p>This is based on starting at a specific day that can be chosen by the user.</p>
  
  <p>So my example is 156 BiWeekly payments (so 155 for the calculations), which works out to 6 years.  If I choose the date of the 1st, I get 10/01/2013 as the start, but 9/11/2019 as the end (First on a Tuesday, last on a Wednesday).</p>
  
  <p>For the 15th (9/15/2013 - a Sunday - to 8/24/2019 - a Saturday)
  For the 20th (9/20/2013 - a Friday - to 8/29/2013 - a Thursday)</p>
  
  <p>So since sometimes it's a day later, and sometimes a day ahead, I can't just +1 to <code>var dd = newDateObj.getDate();</code></p>
  
  <p>I'm really baffled as to what's going on, and I'm hoping someone out there either has some experience with this, or someone that knows what the heck I might be doing wrong.</p>
  
  <p>Thanks in advance for any help you can offer.</p>