#### How does moment.js calculate how many months have passed from one day to another, and which months respectively?

At present, there is a demand like this, is it possible to use moment.js to get a total of several months from one day to another, and those months?

For example, from January 15, 2016 to July 31, 2016, through calculation, it can be obtained that the period between January 1, 2016-02, 2016-03, 2016-04, 2016-05, 2016-06 and 2016-07 has passed

Which great god can help to see how this should be written? There seems to be no such function in moment? It doesn’t matter if you don’t have moment, you can read all js/PHP/JAVA, thank you, please hurry!

Is that it?

Revise one:

Another correction

``````var diffMonths = function(date1, date2) {
var a = moment(date1);
var b = moment(date2);
var diff = b.format('YM') - a.format('YM');
diff = b.format('Y') !  == a.format('Y') ?  Diffplus 2: diff;

Return array.apply ([], newarray (diff plus 1)).map(function(item, index) {
});
};

console.log(diffMonths([2016, 0, 15], [2016, 6, 31]));
console.log(diffMonths([2016, 6, 31], [2016, 7, 1]));
console.log(diffMonths([2016, 6, 1], [2016, 6, 31]));
console.log(diffMonths([2016, 6, 31], [2016, 8, 1]));
console.log(diffMonths([2016, 6, 31], [2017, 8, 1]));
console.log(diffMonths([2016, 6, 31], [2017, 0, 1]));``````

I saw the last time you provided it. If you compare months alone, the last two case won’t work, so I thought of changing it again. Unexpectedly, such a little thing has really been written for a long time.