Restrict date in jquery datepicker based on another datepicker or textbox

jquery datepicker restrict dates in second date field based on selected date in first date field
how to set min date in datepicker using javascript
jquery datepicker set mindate dynamically
set min and max date in jquery datepicker
jquery datepicker disable dates before selected date
bootstrap datepicker set mindate based on another datepicker
datepicker set end date based on start date
how to disable previous date in bootstrap datepicker

I have two text boxes with a datepicker hooked up to them. The text boxes are for start date and end date. The first datepicker is setup so that the user cannot choose a date before today, but can choose any date in the future.

How can I setup the second datepicker so that it cannot choose a date before the date chosen in the first date picker? For example: If today is 12/11/10 and I choose 12/15/10 in the first datepicker, then the second date picker shouldn't be able to choose anything before 12/15/10.

Heres what I have so far:

$("#txtStartDate").datepicker({ minDate: 0 });
$("#txtEndDate").datepicker({});

For example, in this sample code, startDatePicker is selected as 2010-12-12, change event of startDatePicker sets the minDate of endDatePicker 2010-12-13. It locks the cells before this date. This is a sample for what @Victor mentioned..I hope it helps...Regards...Ozlem.

$("#startDatePicker").datepicker({ 
    dateFormat: 'yy-mm-dd',
    changeMonth: true,
    minDate: new Date(),
    maxDate: '+2y',
    onSelect: function(date){

        var selectedDate = new Date(date);
        var msecsInADay = 86400000;
        var endDate = new Date(selectedDate.getTime() + msecsInADay);

       //Set Minimum Date of EndDatePicker After Selected Date of StartDatePicker
        $("#endDatePicker").datepicker( "option", "minDate", endDate );
        $("#endDatePicker").datepicker( "option", "maxDate", '+2y' );

    }
});

$("#endDatePicker").datepicker({ 
    dateFormat: 'yy-mm-dd',
    changeMonth: true
});

[Datepicker] How to set minDate as a date put in another input , Hi, I'm using the datepicker plugin, I want to define minDate as the the mindate accepting the value of date from another textbox..but it is  I have two Date picker start and end. End Date min and max date we are setting based on the selection from start. Min start date for End date picker is start date from start picker selection. Max end date for end date picker is selected start date from start date picker + 7 days.

Update:

The approach above set the minDate only on creation time. I used the onSelect event to change the minDate option of the second datepicker like this:

$("#txtStartDate").datepicker({
  showOn: "both",       
  onSelect: function(dateText, inst){
     $("#txtEndDate").datepicker("option","minDate",
     $("#txtStartDate").datepicker("getDate"));
  }
});

How to restrict date picker selection based on the entry in another , I know how to set the date picker to only make selection available for dates greater than today's date (using JavaScript "min" date attribute), but  By default, the date format of the jQuery UI Datepicker is the US format mm/dd/yy, but we can set it to a custom display format, eg: for European dates dd-mm-yyyy and so on. The solution is to use the date picker dateFormat option. $.datepicker.formatDate( format, date, settings ) Create a new file ’7-datepicker.html’. Define a datepicker

the Tin Man's solution worked for me after adding $("#txtEndDate").datepicker() at the bottom

$("#txtStartDate").datepicker({
  showOn: "both",       
  onSelect: function(dateText, inst){
     $("#txtEndDate").datepicker("option","minDate",
     $("#txtStartDate").datepicker("getDate"));
  }
});

$("#txtEndDate").datepicker(); //it is not working with out this line

Disable certain datepicker dates depended on another datepicker , I have 2 datepicker custom fields(start-date, end-date) and I am trying to disable certain dates from the end-date picker accordingly to the value of from = jQuery​( 'input[name="wpcf-event-start-date[display-only]"' ).attr( 'id' );. Here I am trying to create a page with a textbox where I've an idea to show a CalendarExtender (like in AJAXToolkit) but now I'm trying to get it by using JQuery, the problem is, I can't make the

try this man:

$("#dateTo").datepicker({
    dateFormat: 'dd/mm/yy',
    changeMonth: true,
    changeYear: true,
    minDate:  new Date()
    }).datepicker("setDate", new Date());
$("#dateFrom").datepicker({
    dateFormat: 'dd/mm/yy',
    changeMonth: true,
    changeYear: true,
    onSelect: function(){
        $('#dateTo').datepicker('option', 'minDate', $("#dateFrom").datepicker("getDate"));
    }
    }).datepicker("setDate", new Date());

Restrict date in jquery datepicker based on another , Restrict date in jquery datepicker based on another datepicker or textbox? $("#​startDatePicker").datepicker({ dateFormat: 'yy-mm-dd', changeMonth: true,  How to attach a DatePicker to Textbox in JQuery. "-25y" (shows the today's date minus 25 years) Use the fully resolved ID of your textbox based on the

From a pure UI standpoint, you shouldn't. If the user picks the wrong month on both datepickers, and tries to select the correct month, he has a 50% change of being hindered by the UI. Ideally, you would allow the incorrect selection and display a helpful error message saying the end date should be after the end date.

If you wish to implement your idea : give each datepicker a "change" event that changes the options on the other datepicker appropriately.

Set startDate based on another datepicker date selection (without , Hello all, I am creating some kind of reservation system for a hotel. I have 2 separate datepickers, one for selecting the arrival date and one for  The jQuery UI Datepicker is a highly configurable plugin that adds datepicker functionality to your pages. You can customize the date format and language, restrict the selectable date ranges and add in buttons and other navigation options easily. By default, the datepicker calendar opens in a small overlay when the associated text field gains

How to Set minimum and maximum date in jQuery UI Datepicker, With jQuery UI it is easier to add Datepicker on the textbox element or in any other HTML elements. If you like to restrict access of users to select a  Great advice, Minesh! Almost there: 1) Is it possible to have the first date restricted to todays date as a minimum? Meaning users won't be able to select a past date.

jQuery DatePicker: Validate End date should be greater than Start date, When we use two jQuery DatePickers one for choosing the start date while consisting of two TextBoxes one for selecting the Start (From) date while other for href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.​css". Datepicker with Date Range (From Date & To Date) The following example shows how you can implement date range select functionality in the form input field. This code allows the user to select From Date and To Date, but it restricts the user to select a previous date as To Date.

How to set date to datepicker in javascript, How to set date to datepicker in javascript. DatePicker value based on the modified value of another DatePicker by using the inline edit I have 2 textboxes on my site for pickup date and drop off date both using the jquery date picker. to implement validation to "Restrict Date Range in jQuery UI DatePicker" or "End Date  If you select some date from datepicker the same date is reflected in the second input field whose date format is set as "DD, d MM, yy". Use of beforeShowDay. The following example shows the usage of option beforeShowDay in the datepicker function of JqueryUI.

Comments
  • Thank you! Also your selector for "endDatePicker" should be "#endDatePicker"
  • Simplest and useful-est way.
  • Very good point, I was just about to implement this same concept and then realized I'll just use JavaScript to display the error! Thanks Victor!
  • This is good advice, but how about setting defaultDate instead using a technique similar to Tin Man suggests below? This was my solution.