How do I get the number of days between two dates in JavaScript? -
how number of days between 2 dates in javascript? example, given 2 dates in input boxes:
<input id="first" value="1/1/2000"/> <input id="second" value="1/1/2001"/> <script> alert(datediff("day", first, second)); // goes here? </script>
function parsedate(str) { var mdy = str.split('/'); return new date(mdy[2], mdy[0]-1, mdy[1]); } function daydiff(first, second) { return math.round((second-first)/(1000*60*60*24)); } console.log(daydiff(parsedate($('#first').val()), parsedate($('#second').val())));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input id="first" value="1/1/2000"/> <input id="second" value="1/1/2001"/>
Comments
Post a Comment