title: Change date range in javascript
body: <p>I am trying to set start and end date in date picker where start date is week before current date and end date is week after start date. In certain condition it gives me 0 for start date. Can anyone look into code below and help me to get proper date range when current date is first day of the month or last date of the month. Thanks for your help. </p>
  
  <pre><code> var date = new Date();
  </code></pre>
  
  <p>//When current date was less then 7 in some situation it giving me error. So, I am checking current date and randomly subtract 3. 
      //if current date is less then 7 then get the last day of the previous month
      if (date.getDate() &lt;= 7) {</p>
  
  <pre><code>    day = new Date(date.getFullYear(), date.getMonth(), 0);        
      startdate = day.getDate() - 3;
      month = day.getMonth() + 1;
      year = day.getFullYear();
  
      if (month &lt; 10) month = "0" + month;
      if (day &lt; 10) day = day;
      console.log("App Config: lasy day: " + startdate + "\nmonth: " + month + "\nyear:" + year);
  }
  
  else {
  
      startdate = date.getDate() - 7;
      month = date.getMonth() + 1;
      year = date.getFullYear();
  
      if (month &lt; 10) month = "0" + month;
      if (day &lt; 10) day = day;
  
      console.log("App Config: day: " + startdate + "\nmonth: " + month + "\nyear:" + year);
  }
  
  return month + "/" + startdate + "/" + year;
  </code></pre>