473,468 Members | 1,466 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

javascript to calculate the age

pradeepjain
563 Contributor
Hii ,
I have a field where the user enters his date of birth and after this i need to calculate his/or age ..how to do it.



thanks,
Pradeep
Sep 18 '08 #1
4 3751
Rsmastermind
93 New Member
Please let me know the format of the of the date of birth field so that we can trace out the day,month and year separeately then after the logic is so simple.
Sep 18 '08 #2
pradeepjain
563 Contributor
dd/mm/yyyy is the format
Sep 18 '08 #3
acoder
16,027 Recognized Expert Moderator MVP
Create a new Date object for today's date, get the input and split to get the day/month/year values and then compare. I'm sure you know how to work out someone's age from two dates.
Sep 18 '08 #4
Rsmastermind
93 New Member
Expand|Select|Wrap|Line Numbers
  1. var date_of_birth=$('Id of the field where you have entered the DOB');
  2. var currentDate=new Date();
  3. var day = currentDate.getDate();
  4.   var month = currentDate.getMonth();
  5.   var year = currentDate.getFullYear();
  6.   month+=1;//As month returned starts from 0 like 0 for January
  7.  
  8. var Dob=date_of_birth.split('/');
  9. var Dob_day=Dob[0];
  10. var Dob_month=Dob[1];
  11. var Dob_year =Dob[2];
  12.  
Now you can calculate using different function I know this will be a tricky but I hope you can do because this is one of the basic programming
Sep 19 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: Daniela Nii | last post by:
Hi there, I am looking for a javascript function that someone might have already written to calculate the paid-time-off. Given are the start and end date and time. I need to calculate the...
53
by: Cardman | last post by:
Greetings, I am trying to solve a problem that has been inflicting my self created Order Forms for a long time, where the problem is that as I cannot reproduce this error myself, then it is...
3
by: Tom Cahill | last post by:
The following code will work perfectly on a PC browser, IE or Netscape. However on a Mac browser (IE, Netscape, or Safari) it does not. I have tried it on OSX and OS9. ANy help anyone can offer...
2
by: not | last post by:
Hello All, I am trying to develop a relatively simple self-quiz form in javascript, but I'm having no luck getting it to work. What I am looking for is a script that allow the user to select...
3
by: COHENMARVIN | last post by:
I have a problem that sounds simple but seems impossible with asp.net. I calculate a variable in the Page_Load event, call it X. Then I want my range validators to fire when a textbox value is...
24
by: firstcustomer | last post by:
Hi, Firstly, I know NOTHING about Javascript I'm afraid, so I'm hoping that someone will be able to point me to a ready-made solution to my problem! A friend of mine (honest!) is wanting to...
1
by: pstephen01010101 | last post by:
I've ran out of debugging ideas. If anyone knows why this won't run in IE 6 please let me know. It works fine in Fire Fox 2.0.0.3 and Netscape (version unknown). I suspect there is something basic...
2
by: sarah.kidd | last post by:
Hello I was wondering if someone could please help me. I have created a google map: http://www.cancerpatientgis.com/markers%20test/HospPat_markerstest.html
4
by: =?Utf-8?B?R1ROMTcwNzc3?= | last post by:
Hi Guys, thanks for your help yesterday, I've got one more question, then I think I'm done for now,... Is it possible to insert recordset data in a javascript, for instance I have a javascript...
3
by: vas12 | last post by:
Hi, I have seen emails with this particular message but they do not help me. I get this error only in IE 6 & 7. Firefox, Safari and Opera work fine. Can some one point out what I am doing...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.