JQuery datepicker date range

I am struggling with the below problem and hope you can help me.

I would like to pass from and to dates to JQuery datepicker. User is then only allowed to select a date between those two dates using datepicker.

In other words, all dates less than the from date should be disabled and all dates greater than to date should be disabled.

Given: the date range cannot be more than two months

Pass Aug 8 - Aug 23, 2015 to datepicker
Display datepicker for august 2015 and gray-out dates less than Aug 8 and date greater than Aug 23

Pass Sep 27 - Oct 10, 2015 to datepicker
Display datepicker for Sep and Oct 2015. Gray-out dates less than Sep 27 and dates greater than Oct 10
Errol FarroAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

use the minDate and maxDate options:
  $(function() {
	var range="Aug 8 - Aug 23, 2015";
    $( "#datepicker" ).datepicker( { minDate: getDateFromRange(range,'min')
	                                                   , maxDate: getDateFromRange(range,'max')
  function getDateFromRange(str,selection){
  	var result = str.match(/^([a-z]+)\s+(\d+)[\s-]+([a-z]+)\s+(\d+)\D+(\d{4})$/i);
    		return new Date( Date.parse( '%s %s, %s'.replace('%s',result[1]).replace('%s', result[2]).replace('%s', result[5])) );
    	return new Date( Date.parse( '%s %s, %s'.replace('%s',result[3]).replace('%s', result[4]).replace('%s', result[5])) );

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.