let checkIn = document.getElementById('check-in'); //fecha de arrivo
let checkOut = document.getElementById('check-out'); //fecha de salida
// De aquí obtengo los inputs por id
function howManyDays(date1, date2) {
let totalMs = Math.abs(date2.getTime() - date1.getTime());
let days = totalMs = Math.round(totalMs / msPerDay);
console.log(days)
}
<label for="check">Check-in</label> </div> <input type="date" name="date-in" id="check-in"> </div>
<div class="check">
<div class="block"> <i class="bi bi-calendar-check"></i> <label for="check">Check-out</label> </div> <input type="date" name="date-out" id="check-out"> </div>
And in the second is the function to calculate the days. The problem is that I don't know how to get the values that are entered in the inputs. If I type the date (in the format yy/mm/dd) the function works fine. But the problem is what I describe.
You can use
valueAsDate
for the input to return the date as an objectDate
: