I am using Jquery datepicker which provides me with a texbox and calendar icon.I have two texboxes : 1 is start date and other is enddate.I need to check that end date should not be less than start date using jquery.
Asked
Active
Viewed 4,279 times
3 Answers
3
The jQuery date plugin returns date objects (see the getDate method), which are easily comparable. See this question for example.

Community
- 1
- 1

kgiannakakis
- 103,016
- 27
- 158
- 194
2
First turn the dates with $.datepicker.parseDate(format, string)
to Javascript date. Then use < and > for compare..

Soner Gönül
- 97,193
- 102
- 206
- 364
1
Based on official jQuery UI, the easiest way is to use its date range feature:
<script>
$(function() {
var dates = $( "#from, #to" ).datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 3,
onSelect: function( selectedDate ) {
var option = this.id == "from" ? "minDate" : "maxDate",
instance = $( this ).data( "datepicker" ),
date = $.datepicker.parseDate(
instance.settings.dateFormat ||
$.datepicker._defaults.dateFormat,
selectedDate, instance.settings );
dates.not( this ).datepicker( "option", option, date );
}
});
});
</script>
In your markup:
<div class="demo">
<label for="from">From</label>
<input type="text" id="from" name="from"/>
<label for="to">to</label>
<input type="text" id="to" name="to"/>
</div><!-- End demo -->

yaka
- 914
- 1
- 9
- 16