3

I've this:

<script>    
  var a = '2013-09-07';
  var b = '2013-09-15';
</script>

I want to have the difference in days between these two dates.

I have tried this:

var a = start.format('YYYY-MM-DD');
var b = end.format('YYYY-MM-DD');
var oneday = 86400000;
alert((b-a) / oneday);

But I have a NaN alert().

Thanks.

Francois
  • 275
  • 2
  • 4
  • 11

1 Answers1

3

Try like this:-

var date1 = new Date("09/07/2013");
var date2 = new Date("09/15/2015");
var timeDiff = Math.abs(date2.getTime() - date1.getTime());
var diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24));

Working JSFiddle

Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331