How to control ‘from’ and ‘to’ datepickers so that ‘from’ is always earlier than ‘to’

//Date Picker
$(“#datepicker_from”).datepicker({
format: ‘dd-mm-yyyy’,
autoclose: true,
showButtonPanel: true,
startDate: new Date()
}).on(‘changeDate’, function (selected) {
var startDate = new Date(selected.date.valueOf());
startDate.setDate(startDate.getDate() + 1);
$(‘#datepicker_to’).datepicker(‘setStartDate’, startDate);
}).on(‘clearDate’, function (selected) {
$(‘#datepicker_to’).datepicker(‘setStartDate’,null);
});

$(“#datepicker_to”).datepicker({
format: ‘dd-mm-yyyy’,
autoclose: true,
startDate: new Date()
}).on(‘changeDate’, function (selected) {
var endDate = new Date(selected.date.valueOf());
$(‘#datepicker_from’).datepicker(‘setEndDate’, endDate);
}).on(‘clearDate’, function (selected) {
$(‘#datepicker_from’).datepicker(‘setEndDate’,null);
});

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s