how to calculate age from date of birth in javascript – Calculate age from date of birth to current date. In our day to day programming we often come across business logic that depends on the age of a person.
how to calculate age from date of birth in javascript
i am going to see how to calculate the age of a person using their birth date as input in JavaScript Example with demo.
calculate age from date of birth in javascript
age calculator javascript
function calculate_age(dob) { var diff_ms = Date.now() - dob.getTime(); var age_dt = new Date(diff_ms); return Math.abs(age_dt.getUTCFullYear() - 1970); } console.log(calculate_age(new Date(1982, 11, 4))); console.log(calculate_age(new Date(1962, 1, 1)));
Calculate age using JavaScript
Example 1: Predefined date input
Example 2: dynamic date input
index.html
Calculate Age from Date of Birth
Enter Date of Birth:
Don’t Miss : Age Date Of Birth Calculation With Counter In Javascript
I hope you get an idea about how to calculate age from date of birth in javascript.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.