How to calculated age in javascript between two dates

    Use below function to calculate age
                    var currYear = d.getFullYear(),
                        currMonth = d.getMonth(),
                       currDay = d.getDate();

                    var checkAge = function(birthMonth, birthDay, birthYear) {
                        var age = currYear - birthYear;
                        if (currMonth < birthMonth - 1) {
                            age--;
                        }
                        if (birthMonth - 1 == currMonth && currDay < birthDay) {
                            age--;
                        }
                        return age;
                    };

                    var ageResult = checkAge(11, 10, 2000);

                   //ageResult contains calculated age. Arguments passed to checkDate Month, Day, Year
    5
    Average: 5 (1 vote)

    User login