Count Number of days between 2 dates in javascript
<p>Please help me get the number of days between today's date and some other date.. Here is my <a href="http://jsfiddle.net/vQnHz/" rel="nofollow">example</a></p>

<p>It gives me <code>NaN</code></p>

<p>Here is what I came up with. My <a href="http://jsfiddle.net/vQnHz/3/" rel="nofollow">demo</a></p>

<pre><code>var cellvalue="2011-08-18 11:49:01.0 IST";
var firstDate = new Date();
var secondDate = cellvalue.substring(0, cellvalue.length-4);

alert(diffOf2Dates(firstDate,secondDate));

function diffOf2Dates(todaysDate,configDate)
{
/*var udate="2011-08-18 11:49:01.0";
var configDate=new Date(udate);*/

var oneDay = 24*60*60*1000; // hours*minutes*seconds*milliseconds
var firstDate = todaysDate; // Todays date
var secondDate = new Date(configDate);

var diffDays = Math.abs((firstDate.getTime() - secondDate.getTime())/(oneDay));
console.info(firstDate+", "+secondDate);
//console.info(Math.ceil(diffDays));

return Math.ceil(diffDays);
}
</code></pre>
