Put date range to array <p>I have two JQuery datepicker on my page, I want to put all the days between the two dates to an array.</p> <p>How Can I work it out? Here is my snippet:</p> <pre><code>function mennyi() { var dtFrom = document.getElementById('arrival').value; var dtTo = document.getElementById('departure').value; var dt1 = new Date(dtFrom); var dt2 = new Date(dtTo); var diff = dt2.getDate() - dt1.getDate(); var days = diff; alert(dtTo); document.getElementById("nights").innerHTML = days + " nights"; { $('#arrival').datepicker({ dateFormat: 'dd-mm-yy' }).val(); $('#departure').datepicker({ dateFormat: 'dd-mm-yy' }).val(); var start = new Date(document.getElementById('arrival').value), end = new Date(document.getElementById('departure').value), currentDate = new Date(start), between = [] ; while (end &gt; currentDate) { between.push(new Date(currentDate)); currentDate.setDate(currentDate.getDate() + 1); } $('#lista').html(between.join('&lt;br&gt; '));}; return false; } function isNumeric(val) { var ret = parseInt(val); }; </code></pre> <p>Now it works, but the thing is how can I change the date format, before I put the string into the array? </p>