Complete Code For Getting Numbers of Days Present Between Two Dates In JS.
<!DOCTYPE html> <html> <head> <title>How To Get Numbers of Days Present Between Two Dates In JS</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet"> </head> <style> body { background: black; } </style> <body> <body> <div class="container"> <br/><br/> <div class="text-center"> <h1 id="color" style="color: white;">Get Numbers of Days Present Between Two Dates In JS </h1> </div> <div class="well"> <form action="" method="post" enctype="multipart/form-data"> <label>Enter From Date</label><br> <input type="date" name="date1" id="date1" value=""><br><br> <label>Enter To Date</label><br> <input type="date" name="date2" id="date2" value=""><br><br> <input type="submit" value="submit" class="btn btn-success" id="submit"> </form> <div id="date"></div> <script type = "text/javascript" > document.getElementById("submit").addEventListener("click", function() { // JavaScript program to illustrate // calculation of no. of days between two date // To set two dates to two variables var date1 = new Date(document.getElementById("date1").value); var date2 = new Date(document.getElementById("date2").value); // To calculate the time difference of two dates var Difference_In_Time = date2.getTime() - date1.getTime(); // To calculate the no. of days between two dates var Difference_In_Days = Difference_In_Time / (1000 * 3600 * 24); //To display the final no. of days (result) alert("Total number of days between dates " + date1 + " and " + date2 + " is: " + Difference_In_Days); }); </script> </div> </div> </body> </html>