//below code formats the date in dd/mm/yyyy format and applies the range date of from and as well in the dd/mm/yyyy

// set default dates
 var start = new Date();
 // set end date to max one year period:
 var end = new Date(new Date().setYear(start.getFullYear() + 1));

 $('#fromDate').datepicker({
     format: 'dd/mm/yyyy',
     autoclose: true
 }).on('show', function () { currentDate = $(this).val(); }).on('changeDate', function () { if ($(this).val() === '' || $(this).val() === null) { $(this).val(currentDate).datepicker('update'); 
     //temp to store date
     var temp = $(this).val().split('/');
     var formattedToDate = temp[1] + '/' + temp[0] + '/' + temp[2];
     // set the "toDate" start to not be later than "fromDate" ends:
     $('#toDate').datepicker('setStartDate', new Date(formattedToDate));
 });
 $('#toDate').datepicker({
     format: 'dd/mm/yyyy',
     autoclose: true
 }).on('show', function () { currentDate = $(this).val(); }).on('changeDate', function () { if ($(this).val() === '' || $(this).val() === null) { $(this).val(currentDate).datepicker('update'); 
     var temp = $(this).val().split('/');
     var formattedFromDate = temp[1] + '/' + temp[0] + '/' + temp[2];
     // set the "toDate" start to not be later than "fromDate" ends
     $('#fromDate').datepicker('setEndDate', new Date(formattedFromDate));
 });
0

There are 0 best solutions below