10 lines
368 B
JavaScript
10 lines
368 B
JavaScript
export const calculateAge = (birthdate) => {
|
|
const today = new Date();
|
|
const birthDate = new Date(birthdate);
|
|
let age = today.getFullYear() - birthDate.getFullYear();
|
|
const monthDiff = today.getMonth() - birthDate.getMonth();
|
|
if (monthDiff < 0 || (monthDiff === 0 && today.getDate() < birthDate.getDate())) {
|
|
age--;
|
|
}
|
|
return age;
|
|
}; |