Calculate age in years from a birth date, accounting for month and day.
Code
Generalconst today = new Date();
const birth = new Date(birthDate);
let age = today.getFullYear() - birth.getFullYear();
const m = today.getMonth() - birth.getMonth();
if (m < 0 || (m === 0 && today.getDate() < birth.getDate())) age--;
return age;Parameters
Birth date (YYYY-MM-DD)
Browser·fetch() may be limited by CORS
More JavaScript Snippets
Add Days to Date
Add a specified number of days to a date and return the result in ISO format.
Business Days Between
Calculate the number of business days (weekdays) between two dates. Excludes Saturdays and Sundays, useful for project planning and SLA calculations.
Count Working Days
Count working days (excluding weekends) between dates.
Days Between Dates
Calculate the number of days between two dates.
Days in Month
Get the number of days in a specific month.
End of Day
Get the end of day (23:59:59.999) for a date.