Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 67441

Count the number of days per month between two dates

$
0
0

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>

https://jsfiddle.net/768qrhz3/1/


Viewing all articles
Browse latest Browse all 67441

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>