I managed to get days and weeks between two moments. Nevertheless, I realized that it is much more complicated to get the exact number of months or even years between two moments. Do you have a code snippet to get these?
If I would implement it from scratch I would do it like this:
1. get the year of both moments (lets assume that moment2 is greater than moment1)
2. get the diff between the years:
var year1 = Greg.info(moment1, Date.FORMAT_SHORT)).year;
var year2 = Greg.info(moment2, Date.FORMAT_SHORT)).year;
yearDiff = year2-year1;
3. create a new moment by adding one year to moment1:
moment3 = moment1.add(yearDiff*31449600);
4. compare moment3 with moment2:
if (moment2.greaterThan(moment3) and yearDiff > 0) {
yearDiff -= 1;
}
Nevertheless step 3 does not take leap years into account. Is there a more intelligent and efficient way to get the number of years?
The problem get's even worth for calculating months.....