Skip to content

Instantly share code, notes, and snippets.

@syntaxtoolbox
syntaxtoolbox / age-calculator.js
Last active October 3, 2025 12:59
Calculate Age in Years, Months, and Days with JavaScript
function calculateAge(birthDate) {
const today = new Date();
if (isNaN(birthDate.getTime())) {
return "Invalid birthdate provided";
}
if (birthDate > today) {
return "Birthdate cannot be in the future";
}