Top Ad unit 728 × 90

How to calculate age from date of birth using JQuery | calculate age from date of birth



Sometimes clients demand automatic age calculation while a date of birth is input in HTML-PHP-JQUERY then you may apply the following 4/5 lines of simple code in JS file or JavaScript script file.

Say, you want to fetch an existing date of birth from the database and convert it into an age. Here dob is a variable and res['DOB1'] is storing existing data fetching from the database. Then take another date variable named today and initialized it a current date. That means you are getting two dates one is existing date of birth and another is current date. Now just subtract current date from previous date and divide it with (365.25 * 24 * 60 * 60 * 1000). That's it. Here txtAge is a name of the textbox where converted Age will be shown


dob = new Date(res['DOB1']); //MM/dd/yyyy
var today = new Date();
var vAge = Math.floor((today-dob) / (365.25 * 24 * 60 * 60 * 1000));
$('#txtAge').val(vAge+' Years');
How to calculate age from date of birth using JQuery | calculate age from date of birth Reviewed by Ashok Sen on 14:40:00 Rating: 5

No comments:

Website Design Company at Kolkata All Rights Reserved © 2014 - 2019
Developed by Asenwebmedia

Contact Form

Name

Email *

Message *

Powered by Blogger.