I have three <input>
tags in my code out of which first two accepts date selected using Bootstrap Datepicker, and the last one should show the total number of days selected excluding Saturdays and Sundays.
$(function() {
// create the from date
$('#from-date').datepicker({
autoclose: true,
format: 'dd-mm-yyyy',
}).on('changeDate', function(ev) {
ConfigureToDate();
});
$('#to-date').datepicker({
autoclose: true,
format: 'dd-mm-yyyy',
startDate: $('#from-date').val()
});
// Set the min date on page load
ConfigureToDate();
// Resets the min date of the return date
function ConfigureToDate() {
$('#to-date').val("").datepicker("update");
$('#to-date').datepicker('setStartDate', $('#from-date').val());
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.4/js/bootstrap-datepicker.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.4/css/bootstrap-datepicker.standalone.min.css" rel="stylesheet" />
<input id="from-date" type="text" class="form-control" placeholder="From">
<input id="to-date" type="text" class="form-control" placeholder="To">
<input id="total" class="form-control" placeholder="Total no. of days">
I tried some of the other JS solutions that were discussed on this forum. But I'm unable to achieve this functionality.
I have updated my code(including JS) on the following link JS Fiddle. It would be great if anyone could solve this for me.