… of many things …

… of many things … header image 4

Entries from April 2007

Javascript: Get number of months between two dates

April 2nd, 2007 · No Comments

PLAIN TEXT
JAVASCRIPT:

function monthsBetween(thisDate, thatDate) {

if (thisDate> thatDate) {

return monthsBetween(thatDate, thisDate);

}

 

var number = 0;

if (thatDate.getFullYear()> thisDate.getFullYear()) {

number = number + (thatDate.getFullYear() - thisDate.getFullYear() - 1) * 12;

} else {

return thatDate.getMonth() - thisDate.getMonth();

}

 

if (thatDate.getMonth()> thisDate.getMonth()) {

number = number + 12 + thatDate.getMonth() - thisDate.getMonth();

} else {

number = number + (12 - thisDate.getMonth()) + thatDate.getMonth();

}

return number;

}

[Read more →]

Tags: Computing · Software