title: JavaScript: how to calculate the date that is 2 days ago?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/1296358/subtract-days-from-a-date-in-javascript">Subtract days from a date in javascript</a>  </p>
  </blockquote>
  
  
  
  <p>I have got a JavaScript that basically returns a date that is 2 days ago. It is as follows:</p>
  
  <pre><code>var x;
  var m_names = new Array("January", "February", "March", 
      "April", "May", "June", "July", "August", "September", 
      "October", "November", "December");
  
  var d = new Date();
  var twoDaysAgo = d.getDate()-2;  //change day here
  var curr_month = d.getMonth();
  var curr_year = d.getFullYear();
  var x = twoDaysAgo + "-" + m_names[curr_month] + "-" + curr_year;
  
  document.write(x);
  </code></pre>
  
  <p>Assuming today is 12-December-2012, the above will return the date 10-December-2012. I don't think this will work dynamically as we move forward into a new month, OR, change the day from -2 to -15. It will work only from the 3rd of the month.</p>
  
  <p>How can I modify this so when it is 12-December-2012 today and I want it to return me the date 15 days ago it should be 27-November-2012... and not -3-December-2012?</p>
  
  <p>Any help appreciated. Thanks!
  I'm a Javascript newbie.</p>