title: jQuery Datepicker. 2 datepickers. Restrict range: Max date of 2 weeks from the selected start date
body: <p>I have 2 datepickers "from" &amp; "to". I want to restrict the date range so that for whatever date is selected for the "from" datepicker, the "to" datepicker is restricted to within 2 weeks from that selected "from" date.</p>
  
  <p>For Example: I select 07-15-2018 in "from" datepicker, and I can only select up to 07-29-2018 in "to" datepicker.</p>
  
  <blockquote>
    <p>Current DatePicker Code:</p>
  </blockquote>
  
  <pre><code>&lt;script&gt; $( function() {
  
  var dateFormat = "mm/dd/yy",
    from = $( "#from" )
      .datepicker({
        defaultDate: "+1w",
        changeMonth: true,
        numberOfMonths: 1,
        minDate: 0
      })
      .on( "change", function() {
  
  
       to.datepicker( "option", "minDate", getDate( this ) ); 
  
      }),
    to = $( "#to" ).datepicker({
      defaultDate: "+1w",
      changeMonth: true,
      numberOfMonths: 1
    })
    .on( "change", function() {
      from.datepicker( "option", "maxDate", getDate( this ) );
    });
  
  function getDate( element ) {
    var date;
    try {
      date = $.datepicker.parseDate( dateFormat, element.value );
    } catch( error ) {
      date = null;
    }
  
    return date;
  }
  } );
  &lt;/script&gt;
  </code></pre>