I have two inputs type date and one input type text.
When I pick two dates I would like to know how many dates are picked between per month.
Example:
first-date: 28.08.2020.
last-date: 3.09.2020.
Result: 4 days in 08. month and 3 days in 09. month
What I have right now is script that counts the number of days between two dates
function GetDays() {
var dropdt = new Date(document.getElementById("dep").value);
var pickdt = new Date(document.getElementById("arr").value);
return parseInt((dropdt - pickdt) / (24 * 3600 * 1000));
}
function cal() {
if (document.getElementById("dep")) {
document.getElementById("number-of-dates").value = GetDays();
}
}
<form action=""><input id="arr" type="date" name="arr" onchange="cal()"><input id="dep" type="date" name="dep" onchange="cal()"><input id="number-of-dates" type="text"></form>