I'm trying to count the days between 2 dates. It goes well if both dates are in the same month but not if they are in different. Here is an example where it returns the correct number(1 day):
var oneDay = 24*60*60*1000;
var firstDate = new Date(2017,11,29);
var secondDate = new Date(2017,11,30);
var diffDays = Math.round(Math.abs((firstDate.getTime() - secondDate.getTime())/(oneDay)));
console.log(diffDays);
Here is another example. In this case counting the days between last day of november and the 1st day of december, that should be 1 but returns 2
var oneDay = 24*60*60*1000;
var firstDate = new Date(2017,11,30);
var secondDate = new Date(2017,12,1);
var diffDays = Math.round(Math.abs((firstDate.getTime() - secondDate.getTime())/(oneDay)));
console.log(diffDays);
I have observed that it returns wrong number if the months are different and if one or both months are conformed by less than 31 days, it adds the number of days missing from the month(s) that have less that 31, in this case 1 because november has 30 days and december 31, 1 + 1(missing days) = 2. Any Idea of how to get it right is very welcomed.