<script>
function declOfNum(number, titles) {
cases = [2, 0, 1, 1, 1, 2];
return number+" "+titles[ (number%100>4 && number%100<20)? 2 : cases[(number%10<5)?number%10:5] ];
}
function birthDateToAge(b) {
var n = new Date(), b = new Date(b),
age = n.getFullYear() - b.getFullYear();
return n.setFullYear(1972) < b.setFullYear(1972) ? age - 1 : age;
}
document.write( declOfNum(birthDateToAge("1880-07-15"), ['год', 'года', 'лет']) );
</script>
|