2 DatePickers (Start & End Dates): Restrict date range

2 DatePickers (Start & End Dates): Restrict date range

I'm using 2 DatePickers (Start & End Dates). I want to restrict the date range so that for whatever date is chosen for the Start Date, the End Date can be up to 2 weeks after the Start Date. How would I do this?

For Example: I choose 07/15/2018 as the Start Date, so the End Date can be from 07/16-07/29 .

Here's my current DatePicker code:

  1.  <script>
      $( 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;
        }
      } );
      </script>