Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JavaScriptQuestions JavaScript calculate age from date of birth
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


ratna rathor
JavaScript calculate age from date of birth
1 Answer(s)      2 years and 4 months ago
Posted in : JavaScript Questions


How to calculate age from date of birth?

Advertisement
View Answers

May 16, 2012 at 3:37 PM


<html>
<head>
<script type="text/javascript">
    function ageCount() {
        var date1 = new Date();
        var  dob= document.getElementById("dob").value;
        var date2=new Date(dob);
        var pattern = /^\d{1,2}\/\d{1,2}\/\d{4}$/; //Regex to validate date format (dd/mm/yyyy)
        if (pattern.test(dob)) {
            var y1 = date1.getFullYear(); //getting current year
            var y2 = date2.getFullYear(); //getting dob year
            var age = y1 - y2;           //calculating age 
            document.write("Age : " + age);
            return true;
        } else {
            alert("Invalid date format. Please Input in (dd/mm/yyyy) format!");
            return false;
        }

    }
</script>
</head>
<body>
Date of Birth(dd/mm/yyyy):
<input type="text" name="dob" id="dob" />
<input type="submit" value="Age" onclick="ageCount();">
</body>
</html>

Description: Here you can use regular expression to validate date format. If inputted date of birth is in form of dd/mm/yyyy then count age by subtracting dob into current date. you can also take specified date in place of current date to count age. getFullYear() is used here to get year of specified date.



Related Tutorials/Questions & Answers:
JavaScript calculate age from date of birth
JavaScript calculate age from date of birth  How to calculate age from date of birth?   <html> <head> <script type="text/javascript"> function ageCount() { var date1 = new Date
How automatically calculate age based on date of birth and current date using jsp and servlet?
How automatically calculate age based on date of birth and current date using jsp and servlet?  when user enters the Date of birth in one textbox then automatically age will be display on another textbox. event:Onlick Event
Advertisements
Calculate Age using current date and date of birth
Calculate Age using current date and date of birth In this section you will learn how to calculate the age. For this purpose, through the code, we have prompted the user to enter current date and date of birth in a specified format. Now
Determining the actual age from date of birth in Java
Determining the actual age from date of birth in Java... your complete date of birth (year, month and day of month) and gives you the exact... any invalid year or month or day for your date of birth.   Here
Calculate an average Age of my Class?
Calculate an average Age of my Class?  average age of my class
how can you calculate you your age in daies??
how can you calculate you your age in daies??  **hi, I am beginner in java! can any one help me to write programm to calculate age in daies... of your date of birth: "); int day=input.nextInt
age calculator
age calculator  sir , actually m working on a project where i want the user to enter his date of birth in a jtextfield .and on doing so his age should b displayed in the next textfield automatically....plz help
sql query to get name,age,phone,address from tables t1,t2,t3,t4,t5 ..
sql query to get name,age,phone,address from tables t1,t2,t3,t4,t5 ..   this is for single table : query ="SELECT name , age , pwd , phone... by name"; i want for 12 tables : i want to fetch name age pwd phone address from 12
Week calculate start from friday
Week calculate start from friday  My problem is to calculate how many weeks have a month. Note that my weeks have to start on Friday! I have three combo boxes. First display year. Second one display month. Third one display
JavaScript Date Difference
JavaScript Date Difference...() that returns the time (in milliseconds) elapsed from 1st January, 1970 to the current Date...;Date Difference</h2> <script type="text/javascript"> var
javascript date picker - Date Calendar
javascript date picker  how to insert a date picker user control in a html/jsp using javascript??? please help, it's urgent.  Hi Friend, Please visit the following links: http://www.roseindia.net/javascript
Date object using JavaScript
Date object using JavaScript  What's the Date object using JavaScript
javascript questions on date
javascript questions on date  how to add some days to an existing date
how to generate the pdf file with scroolbar from jsp age - JSP-Servlet
how to generate the pdf file with scroolbar from jsp age  How to generate the pdf file with scroolbar from jsp.i am not able to see the all the columns in pdf file now .it is very urgent for me plz help
javascript tomorrow date.
javascript tomorrow date.  Hi, how can I display tomorrow's date using javascript?   <html> <head> <title>Date after current date</title> <script type="text/javascript"> var mydate= new
javascript yesterday date.
javascript yesterday date.  Hi, How can I display the yesterday's... date</title> <script type="text/javascript"> var mydate= new Date...;/head> </html> Description: In javascript whenever you write new Date
javascript date difference in years
javascript date difference in years  I want to find the difference between two dates with respect to years. I am using javascript. Please help.   <html> <head> <script type="text/javascript"> var
javascript date comparison
javascript date comparison  How to compare dates and display... language="JavaScript"> var date1 = new Date("jan, 25, 2010"); var today = new Date(); var difference = today - date1; var days =parseInt(difference
javascript current date and time.
javascript current date and time.  How can we display current date and time using javascript?   <html> <head> <title>Current date and time</title> </head> <script type="text/javascript
javascript date difference in months
javascript date difference in months  How can I find the difference...; <head> <script type="text/javascript"> var date1=new Date(); var...; Description: In javascript whenever you write new Date() it shows the current date
javascript date difference in days.
javascript date difference in days.   I want to find the difference between two dates in terms of days. I am using javascript. Please help.   <html> <head> <script type="text/javascript"> var date1
JavaScript Validate UK Date
JavaScript Validate UK Date  How to Validate UK Date in JavaScript... if (!validformat.test(input.value)) alert('Invalid Date Format. Please correct.') else{ //Detailed check for valid date ranges var
date format in javascript
date format in javascript  display date format as dd/mm/yyyy and day... help me. thank u var date=/^\d{2}\/\d{2}\/\d{4}$/ if(document.userform.joindate.value.search(date)==-1) { alert("please enter date format as dd/mm/yyyy
Mysql Date from Date
Mysql Date from Date       Mysql  Date from Date Time in Mysql return the Current  date. Understand with Example The Tutorial illustrate an example from 'DateTime
age calculation
age calculation  pls send me the age calculation validation coding in java script. i'm waiting for ur reply
JavaScript Show Date
JavaScript Show Date..., we are going to display the current date using JavaScript. You can see... Date</h2> <script type="text/javascript"> var date = new
JavaScript parse date
JavaScript parse date..., you will learn how to parse the date in JavaScript. JavaScript provides the function parse() that takes a date in string format and returns the equivalent
start date and end date validation in javascript - Ajax
start date and end date validation in javascript  hi, i am doing web surfing project. pls guide me for my project. i want start date and end validations in javascript. end date should be greater than start date if so less than
compare age with dob - WebSevices
* from tableName where date like '2008-12-20'; Thanks... sandeep kumar...compare age with dob  Thanks for your quick reply. but I need exact... as Age like(18). but we dont have specified age field for fetching. instead of age
javascript date validation using regex
javascript date validation using regex  Hi, I want to validate the date using javascript. Please help.   <html> <head> <title>Validating Date format</title> <script type="text/javascript">
calculate total hours by start time and end time in javascript - Ajax
calculate total hours by start time and end time in javascript  hi, i am doing Web surfing project. i used start and end timepicker field.it works... my doubts. how to calculate total hours by using start and end time field
Advertisements
 

 

 

DMCA.com