This is a discussion on "Age Calculation" within the JavaScript Forum section. This forum, and the thread "Age Calculation are both part of the Program Your Website category.
|
|
|
|
|
![]() |
||
Age Calculation
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
|||
|
Age Calculation
I have searched for a generic javascript age calculation function, with no avail. I need to return the age in years, by substracting two dates, allowing for +/- 1 depending on birth month.
Using: ASP - Javascript Form Name: Dui 1st Date: DOB -- mm/dd/yyyy 2nd Date: DateWritten-- mm/dd/yyyy Return to: Age - int Can anyone please assist, or point me to a generic script that would serve my purpose. Thanks Ernest |
|
|
|
|||
|
Re: Age Calculation
Hello.
This may be a really illogical way to approach this, but you could have the DOB as variable dob and then statement it as such:
Thanks, Dan Williamson Last edited by Dan Williamson; May 8th, 2006 at 19:42. |
|
|||
|
Re: Age Calculation
Thanks for the response.....Not exactly what I'm looking for. What I need is something on the order of the script below.
--------------------------------------------------------- <script language="JavaScript"> function age() { var DOB = (document.Dui.DOB.value); var DateWritten = (document.Dui.DateWritten.value); If Month(DateWritten) < Month(DOB) Or (Month(DateWritten) = _ Month(DOB) And Day(DateWritten) < Day(DOB)) Then document.Dui.Age.value = Year(DateWritten) - Year(DOB) - 1 Else document.Dui.Age.value = Year(DateWritten) - Year(DOB) End If End Function } </script> --------------------------------------------------------------- When I run the above script, I get no results: "Error on page". Thanks Ernest Last edited by ekendricks; May 9th, 2006 at 00:41. |
|
|||
|
Re: Age Calculation
I dont know much about JavaScript but this page seems to do what you want
http://members.aol.com/abgenealogy/agecalc.htm I'm sure if you looked through their source code you could piece together what you want and change it to do what you need. |
|
|||
|
Re: Age Calculation
Ive done some more digging and something like
age=yearCurrent-yearOfBirth; if(monthOfBirth-monthCurrent<0)age--; else if(monthOfBirth-monthCurrent==0) if(dayOfBirth-dayCurrent<0)age--; |
![]() |
| Tags |
| age, calculation |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| total days calculation | melisa | JavaScript Forum | 0 | May 25th, 2007 01:17 |
| JS option value calculation / validation | stroodle01 | JavaScript Forum | 0 | Mar 15th, 2007 18:32 |
| Please help with calculation | edp1959 | JavaScript Forum | 0 | Feb 25th, 2007 11:42 |
| Arithmetic Calculation | Monie | Databases | 0 | Oct 18th, 2006 11:01 |
| 24 hour time calculation | kinjiro | JavaScript Forum | 9 | Sep 20th, 2003 06:40 |