Posted inJavaScript / jQuery

how to calculate age from date of birth in javascript?

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.

I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.

Leave a Reply

Your email address will not be published. Required fields are marked *

We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype