Skip to content Skip to sidebar Skip to footer

Setting Mindate To Prevent From Choosing Enddate Before Start Date

I have a start date and end date for me to choose the date. I am using jQuery datepicker library. This is how my function looks like for now: $(function() { $('.txtEndDate

Solution 1:

You can disable past dates using minDate property of datepicker plugin, as below.

$(".txtEndDate").datepicker({
            minDate: newDate(),  // Add this to diсable past datechangeMonth: true,
            changeYear: true,
            showOn: 'button',
            buttonImage: '../../../images/calendar.png',
            buttonImageOnly: true,
            title:'Click to open calendar',
            alt:'Click to open calendar'
        });

Solution 2:

use the below code it will help you to prevent selecting old date from today.

minDate : 0// for current dateminDate: newDate(2007, 1 - 1, 1) // for particular minDate 

$("input.DateFrom").datepicker({
    minDate: 0  
});
<linkrel="stylesheet"href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"><linkrel="stylesheet"href="/resources/demos/style.css"><scriptsrc="https://code.jquery.com/jquery-1.12.4.js"></script><scriptsrc="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script><inputclass="DateFrom">

code to end date less that start date please refer the code :-

  $("#StartDate").datepicker({
        numberOfMonths: 2,
        onSelect: function(selected) {
          $("#EndDate").datepicker("option","minDate", selected)
        }
    });
    $("#EndDate").datepicker({ 
        numberOfMonths: 2,
        onSelect: function(selected) {
           $("#StartDate").datepicker("option","maxDate", selected)
        }
    });  

Post a Comment for "Setting Mindate To Prevent From Choosing Enddate Before Start Date"