I have downloaded games and reading loads, and still spent about 3 hours on this. I can’t believe it is so complicated.
I have a Javascript / JQuery application, I have the moment.js plugin installed. I am writing a POS application and I need to calculate the difference in days between two dates, so I can warn the user that the returned item may be too old to return.
I found this code in JS that looks good and seems to be a popular way to do this, although I just couldn't get it to work
var oneDay = 24*60*60*1000;
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)));
I also tried this with Moment.js, which again looks very neat
var a = moment([2007, 0, 29]);
var b = moment([2007, 0, 28]);
var x = a.diff(b);
. "oDate.diff ", ...
todaysDate = moment(new Date()).format('YYYY, MM, DD');
oDate = moment(result.Order.created).format('YYYY, MM, DD');
var diffDays = oDate.diff(todaysDate, 'days');
, oDate. , .
. , todaysDate oDate console.log,
todaysDate - 2016, 09, 14
oDate - 2016, 09, 12
?