Home Answers Viewqa JavaScriptQuestions JavaScript calculate age from date of birth

 
 


ratna rathor
JavaScript calculate age from date of birth
1 Answer(s)      a year ago
Posted in : JavaScript Questions

How to calculate age from date of birth?
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 Pages:
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
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
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
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
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
Calculate an average Age of my Class?
Calculate an average Age of my Class?  average age of my class
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 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
calculate the time ..
calculate the time ..  [CODE] Elapsed Time Example <script type="text/javascript"> var startTime = null...() { startTime = new Date(); alert("Time Started
Javascript calculate number of days between two dates
Javascript calculate number of days between two dates In this tutorial, you will learn how to calculate number of days between two dates.For this, you need to use the Date object  to retrieve the Date's millisecond value
Calculate Month Difference in mysql - SQL
_No, (month(sysdate())-month(Entry_Date)) from monthlytransaction ; so that based...Calculate Month Difference in mysql  hi , i am rahul.Can anybody... is based on date. eg 2008-05-12 to 2008-09-25(4 months) And it should also take care
JavaScript - JavaScript Tutorial
but experienced programmer can also learn many things from this JavaScript tutorial series... how to immediately put JavaScript to validate forms, calculate values, work... This namedItem() method of JavaScript can be used to achieve the named items from
Swing Program
Swing Program  Write a java swing program to calculate the age from given date of birth
Java swing
Java swing  Write a java swing program to calculate the age from given date of birth
JavaScript Date Function
JavaScript Date Function Many language provide special functions for Date... the functions. JavaScript Date Function Example: <html> <head>...()); var d=new Date(); document.write("<br/><b>Miliseconds from
Mysql Date Manipulation
and birth from the table :- The Query below find out the field difference in age... table Person(name VARCHAR(20),birth DATE,death DATE); Output...)) -> as age from person -> where death is not null; Output
vaidate a date from datepicker in javasript
vaidate a date from datepicker in javasript  validation should be the user should be alerted wen a future date is selected..validation can be done in javascript or jsp itself
date
date  can u tell me how to calculate difference between a user provided date and the system date in java
date
date  can u tell me how to calculate difference between a user provided date and the system date in java
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
how to format date from yyyy-mm-dd to dd-mm-yyyy
how to format date from yyyy-mm-dd to dd-mm-yyyy  <!DOCTYPE html... to calculate the nos. of days between two dates, the date format is in "yyyy-mm-dd", so...;body> <html> <head> <script type="text/javascript">
JavaScript check if date is between two dates.
JavaScript check if date is between two dates.  Check if date is between two dates?   <html> <head> <title>Date before...: -This example is taking 2 dates from user and one date to check either
Date format - Date Calendar
Date format  Hi All, I am getting a date from database as a format 2010-15-07.I need to change it to 07/15/2010 and display it on my date field.Every time i need to check the format of the date field and make sure the correct
Locale Specific Date validations through JavaScript/Ajax...
Locale Specific Date validations through JavaScript/Ajax...  Hi, I....), how to manipulate date validations through JavaScript or Ajax? Thanks in Advance, Sreenivasulu Arveti.   Hi, You can write normal JavaScript
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
date function
date function  Write a JavaScript program to read a date from user.... Display the day no from the date 2. Display the year from the date 3. Display the month from the date 4. Change the date to next day 5. Change the year
Date validation
Date validation  How to validate date in jsp? That is i have a textbox which will have the value from the date picker. How to validate the date... the following links: http://www.roseindia.net/javascript/javascript
javascript questions on date
javascript questions on date  how to add some days to an existing date
How to calculate attending hours?
How to calculate attending hours?  I need to calculate attending hours of a employee in a day in my project to make their monthly salary . By using work starting time and ending time. How should I do it using Date class? Or any
timespan in javascript
timespan in javascript  How to calculate timespan in Java and JavaScript?   stringToDate: function(string) { var matches; if (matches = string.match(/^(\d{4,4})-(\d{2,2})-(\d{2,2})$/)) { return new 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
Retrieve date from MYSQL database
Retrieve date from MYSQL database In this tutorial, you will learn how to retrieve date from database. Storing and Retrieving dates from the database... of birth of persons from the database table. For this, we have used the TimeStamp
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 - JavaScript Tutorial
from this JavaScript tutorial series. This JavaScript Tutorial will teach you... JavaScript Tutorials is one of the best Quick reference to the JavaScript. In this JavaScript reference you will find most of the things about java script
JavaScript - JavaScript Tutorial
from this JavaScript tutorial series. This JavaScript Tutorial will teach you... JavaScript Tutorials is one of the best Quick reference to the JavaScript. In this JavaScript reference you will find most of the things about java script
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
javascript  hi, I was actually working on to calculate the number of days between two dates of yyyy-mm-dd format using javascript, and when i click on button then number of days should be display in textbox
DATE
DATE  I have the following as my known parameter Effective Date... from 21-08-2012 till wednesday(22-08-2012) and from thursday my second cycle of calcultion starts My question is how to find the date of Thursday This cycle
Calculate factorial of a number.
Calculate factorial of a number.  How to calculate factorial of a given number?   import java.io.BufferedReader; import java.io.IOException... Integer.parseInt(). For loop from 1 to num-1 calculating the factorial value of num
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
Javascript get Date And Selected Option Text
Javascript get Date And Selected Option Text In this tutorial we will learn about how to get Date from the textbox and displayed as Date as well as how... explains you that how to display the date and the selected option text in Javascript
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

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.