title: JavaScript calculating date from today date to 7 days before
body: <p>I am calculating 12 days before date from today date. But it does not return the correct date.
  For example, for today dat, 11/11/2013 in (mm/dd/yyyy), it returns 10/30/2013 when it should return 10/31/2013.</p>
  
  <p>Here is the code</p>
  
  <pre><code>var d = new Date();
  d.setDate(d.getDate() - 12);
  d.setMonth(d.getMonth() + 1 - 0);
  var curr_date = d.getDate();
  var curr_month = d.getMonth();
  var curr_year = d.getFullYear();
  if (curr_month &lt; 10 &amp;&amp; curr_date &lt; 10) {
      var parsedDate = "0" + curr_month + "/" + "0" + curr_date + "/" + curr_year;
      alert(parsedDate);
  } else if (curr_month &lt; 10 &amp;&amp; curr_date &gt; 9) {
      var parsedDate = "0" + curr_month + "/" + curr_date + "/" + curr_year;
      alert(parsedDate);
  } else if (curr_month &gt; 9 &amp;&amp; curr_date &lt; 10) {
      var parsedDate = curr_month + "/" + "0" + curr_date + "/" + curr_year;
      alert(parsedDate);
  } else {
      var parsedDate = curr_month + "/" + curr_date + "/" + curr_year;
      alert(parsedDate);
  }
  </code></pre>