Age Calculation

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.



Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old May 8th, 2006, 17:34
Junior Member
Join Date: Aug 2003
Location: USA
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
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
Reply With Quote

  #2 (permalink)  
Old May 8th, 2006, 19:39
Junior Member
Join Date: May 2006
Location: Manchester. UK
Age: 17
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
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:

HTML: Select all
<script type="text/javascript">
<!--
var dob = "mm/dd/1991";

if (dob == "mm/dd/1992")
{
document.write("Happy Birthday");
}
if (dob == "mm/dd/1990")
{
document.write("Happy Birthday");
}
if (dob == "mm/dd/1991")
{
document.write("Happy Birthday");
}
//-->
</script>
This is a really time-wasted way of doing it, but it could work. I don't know Javascript very well by the way

Thanks,
Dan Williamson

Last edited by Dan Williamson; May 8th, 2006 at 19:42.
Reply With Quote
  #3 (permalink)  
Old May 9th, 2006, 00:35
Junior Member
Join Date: Aug 2003
Location: USA
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
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.
Reply With Quote
  #4 (permalink)  
Old May 10th, 2006, 10:53
Up'n'Coming Member
Join Date: Nov 2005
Location: England
Posts: 71
Thanks: 0
Thanked 0 Times in 0 Posts
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.
Reply With Quote
  #5 (permalink)  
Old May 10th, 2006, 10:56
Up'n'Coming Member
Join Date: Nov 2005
Location: England
Posts: 71
Thanks: 0
Thanked 0 Times in 0 Posts
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--;
Reply With Quote
Reply

Tags
age, calculation

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

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


All times are GMT. The time now is 19:11.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43