title: Javascript - Calculate date 1 year/3 months/1 month ago from current date (dd-mm-yyyy)
body: <p>I have a dropdown box that contains 3 options..monthly, quarterly and yearly. I am trying to populate 2 fields when either of the options are selected. The start date will be the current date, and I want to work out the end date depending on the option selected. So far I have this.</p>
  
  <p>HTML: </p>
  
  <pre><code>&lt;select name="date_range" class="date_range"&gt;
      &lt;option value="None"&gt;Please select a date range&lt;/option&gt;
      &lt;option value="Yearly"&gt;Yearly&lt;/option&gt;
      &lt;option value="Quarterly"&gt;Quarterly&lt;/option&gt;
      &lt;option value="Monthly"&gt;Monthly&lt;/option&gt;
  &lt;/select&gt;
  
  &lt;p&gt;Start Date&lt;/p&gt;
      &lt;input type="text" name="start_date" id="start_date" /&gt;
  &lt;p&gt;End Date&lt;/p&gt;
      &lt;input type="text" name="end_date" id="end_date" /&gt;
  </code></pre>
  
  <p>JavaScript:</p>
  
  <pre><code>$(function() {
      $('.date_range').change(function(){
      var date = new Date();
      console.log(date);
      });
  });
  </code></pre>
  
  <p>The console.log gives me the following: </p>
  
  <pre><code>Wed May 01 2013 19:42:42 GMT+0100 (GMT Daylight Time)
  </code></pre>
  
  <p>Both the 'start_date' and end_date' fields use datepicker and currently have a format of dd-mm-yyyy. How would I calculate the correct date range (month, quarterly or yearly) from the current date to the correct format and set the value of the both fields (with the 'dd-mm-yyyy' format). </p>
  
  <p>I have come across Moment.js and datejs which I may look into using if the problem is too complicated. Cheers for any help in advance.</p>