I have three <input>
tags in my code out of which two are populated with dates chosen from Bootstrap-Datepicker.
<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-count" class="form-control" placeholder="Total no. of Years, Months and Days.">
I would like to calculate the difference between these two dates in terms of Years, Months and Days, and display it in total-count
. I went through some examples on Stack Overflow, wasn't able to achieve/find an ideal solution, because it was really confusing to me. If anyone could help me solve this, it would be of great help.
Below is my JS code. I've updated the whole code Here
$(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());
}
});