get the difference between two date in days in javascript or moment.js

Hello,
  How do I get the difference between 2 date in days

e,g diff (2015-03-15T00:00:00",today) = 2

I tried moment.js .. but it return "2 days ago" .. I would like a number

var x =moment("2015-03-15T00:00:00", "YYYY-MM-DDThh:mm:ss").fromNow();

Thanks
chand pbAsked:
Who is Participating?
 
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
http://jsbin.com/daguma/1/edit?html,output
<!DOCTYPE html>
<html>
<head>

  <script src="http://momentjs.com/downloads/moment.js"></script>
  <script>
    var x =moment("2015-03-15T00:00:00", "YYYY-MM-DDThh:mm:ss");
var y = moment("2015-03-13T00:00:00", "YYYY-MM-DDThh:mm:ss");

alert(x.diff(y, 'days')); 
  </script>
  <meta charset="utf-8">
  <title>padas</title>
</head>
<body>

</body>
</html>

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.