This page is all about put some validation between two dates picker where to date shouldn’t less than from date.
That means End date Should be Greater than the Start date. Here I have given a simple example for jquery datepicker.
HTML
1 2 | <input id="booking_from_date" class="form-control" name="booking_from_date" type="text" value="" /> <input id="booking_to_date" class="form-control" name="booking_to_date" type="text" value="" /> |
Jquery
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | <script type="text/javascript"> $( function() { var dateToday = new Date(); var dateFormat = "mm/dd/yy"; beginDate = $( "#booking_from_date" ) .datepicker({ changeMonth: true, minDate:dateToday }) .on( "change", function() { endDate.datepicker( "option", "minDate", getDate( this ) ); }), endDate = $( "#booking_to_date" ).datepicker({ changeMonth: true, minDate:dateToday }) .on( "change", function() { beginDate.datepicker( "option", "maxDate", getDate( this ) ); }); function getDate( element ) { var date; try { date = $.datepicker.parseDate( dateFormat, element.value ); } catch( error ) { date = null; } return date; } } ); </script> |
Booking from Date:
Booking To Date: