I've googled loads and read loads, and so far wasted about 3 hours on this. I can't believe its so tough.
I'm writing a POS application, and I need to calculate the difference in days between two dates, so I can warn the user that a particular returned item might be too old to be returned.
I found this code in JS which looks good and seems to be the popular way to do it, although I just couldn't get it to work
var oneDay = 24*60*60*1000; // hours*minutes*seconds*milliseconds
var firstDate = new Date(2008,01,12);
var secondDate = new Date(2008,01,22);
var diffDays = Math.round(Math.abs((firstDate.getTime() - secondDate.getTime())/(oneDay)));
var a = moment([2007, 0, 29]);
var b = moment([2007, 0, 28]);
var x = a.diff(b);
todaysDate = moment(new Date()).format('YYYY, MM, DD');
oDate = moment(result.Order.created).format('YYYY, MM, DD');
var diffDays = oDate.diff(todaysDate, 'days');
Do no use format function before taking the difference. . .once you call format it wont be moment object anymore. format function converts it into a string.
todaysDate = moment(new Date()); oDate = moment(result.Order.created); var diffDays = oDate.diff(todaysDate, 'days');