I would like to calculate a users age when a string is entered however it has to be in a particular order currently this works only in one order I would like it to be day/month/year, currently it only works in month/day/year
function getAge(dateString) {
var today = new Date();
var birthDate = new Date(dateString);
var age = today.getFullYear() - birthDate.getFullYear();
var m = today.getMonth() - birthDate.getMonth();
if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) {
age--;
}
return age;
}
console.log('age: ' + getAge("16/01/1972")); **//01/16/1972 works!**