Created
February 27, 2009 04:39
-
-
Save jacaetevha/71291 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment