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

  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();

chand pbAsked:
Who is Participating?
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:,output
<!DOCTYPE html>

  <script src=""></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')); 
  <meta charset="utf-8">


Open in new window

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.