Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > Finding Age from Date of Birth

Reply
Thread Tools

Finding Age from Date of Birth

 
 
Aaron Bertrand [MVP]
Guest
Posts: n/a
 
      01-04-2004
> ok, i have a date stored in a field, i want to transplant this data into
> that script so it can return another variable whihc is the date...


I don't understand your narrative. Could you show a few sample rows from
your database, and what you want presented on the ASP page?


 
Reply With Quote
 
 
 
 
Brynn
Guest
Posts: n/a
 
      01-04-2004

If BUT MIND could only be proper ASP syntax ... that would ROCK



On 04 Jan 2004 19:28:33 GMT, "Evertjan."
<(E-Mail Removed)> wrote:

>Bob Barrows wrote on 04 jan 2004 in
>microsoft.public.inetserver.asp.general:
>> UncleWobbly wrote:
>>> age = datediff("y",birthdate,now)
>>>
>>> gives it in whole years ("y")
>>>

>> No, it doesn't. See Aaron's faq article for the reason.

>
>It should.
>
>IF
>the value of birthdate includes the exact time of birth
>AND
>the servertime is in the same timezone
>as in which the birthdate was specified
>AND
>the servertime is in the same daylight saving correction
>as in which the birthdate is specified
>THEN
>age would give the correct number of years
>BUTFOR
>the crazy notion that you get your additional year
>at 00:00 local time, independent of the sometimes different
>local time of the place of birth
>AND
>independent of the exact time of birth anyhow
>SO
>this calls for first getting the definition of "age" right
>ANDTHEN
>correcting the inputvalues of DateDiff to that definition
>BUTMIND
>that there can be a conciderable difference in de time of the first
>appearence of the head in the case of a "normal" [=normalized?] birth and
>the final delivery of the feet q.q. other hinter parts
>SO
>event the date of birth could be agued to be on different dates
>AND
>the birth could have happened in an aeroplane
>OR
>on the international dateline
>OR
>exactly on one of the poles
>OR
>on a spaceship
>OR
>another planet
>INWHICHCASE
>all odds are off
>ENDIF
>
>
>
>--
>Evertjan.
>The Netherlands.
>(Please change the x'es to dots in my emailaddress)


 
Reply With Quote
 
 
 
 
Brynn
Guest
Posts: n/a
 
      01-04-2004

I think I am going to write a function to be all exclusive ...
including variables for being born in an airplane on the international
dateline

LOL

On 04 Jan 2004 19:28:33 GMT, "Evertjan."
<(E-Mail Removed)> wrote:

>Bob Barrows wrote on 04 jan 2004 in
>microsoft.public.inetserver.asp.general:
>> UncleWobbly wrote:
>>> age = datediff("y",birthdate,now)
>>>
>>> gives it in whole years ("y")
>>>

>> No, it doesn't. See Aaron's faq article for the reason.

>
>It should.
>
>IF
>the value of birthdate includes the exact time of birth
>AND
>the servertime is in the same timezone
>as in which the birthdate was specified
>AND
>the servertime is in the same daylight saving correction
>as in which the birthdate is specified
>THEN
>age would give the correct number of years
>BUTFOR
>the crazy notion that you get your additional year
>at 00:00 local time, independent of the sometimes different
>local time of the place of birth
>AND
>independent of the exact time of birth anyhow
>SO
>this calls for first getting the definition of "age" right
>ANDTHEN
>correcting the inputvalues of DateDiff to that definition
>BUTMIND
>that there can be a conciderable difference in de time of the first
>appearence of the head in the case of a "normal" [=normalized?] birth and
>the final delivery of the feet q.q. other hinter parts
>SO
>event the date of birth could be agued to be on different dates
>AND
>the birth could have happened in an aeroplane
>OR
>on the international dateline
>OR
>exactly on one of the poles
>OR
>on a spaceship
>OR
>another planet
>INWHICHCASE
>all odds are off
>ENDIF
>
>
>
>--
>Evertjan.
>The Netherlands.
>(Please change the x'es to dots in my emailaddress)


 
Reply With Quote
 
Brynn
Guest
Posts: n/a
 
      01-04-2004
Here is a function where you don't have to worry about the leap year.

It first takes the currentYear - birthYear - 1

Then it decides whether it needs to add a year(i.e if they had their
bday). First by just making a number out of the month and day ... it
makes the day 2 digits by adding a '0' in front of a single digit day.
Then puts month and day into one number .. like this

feb 2 = 202
july 10 = 710
oct 8 = 1008
dec 20 = 1220

and yes feb 29 = 229

Then if today is 301 it doesn't care ... 228 and 229 are both less
than 301.

I also added a part to compare ONLY the times ... if the day
comparison = 0 ... i.e. today is there bday

now, if you don't send a time with your date ... no problem ... it
will count today as being their new age

Tell me what you think ... I can clean up the code a bit if anyone
wants me to


<%
Function yearsOld(birthDate)
Dim currentDate, monthDayComparison, addYear: currentDate =
Now()

Dim birthDay, currentDay: birthDay = Day(birthDate):
currentDay = Day(currentDate)

'// Lets take the Date() BS out of the picture!!!
'//Compare Days by making a number out of month & day
.... feb 29 = 229 while oct 8 = 1008
If Len(birthDay) = 1 Then: birthDay = "0" & birthDay:
End If
If Len(currentDay) = 1 Then: currentDay = "0" &
currentDay: End If
monthDayComparison = Int(Int(Month(currentDate) &
currentDay)) - Int(Month(birthdate) & birthDay)


If monthDayComparison > 0 Then '//had birthday this
year
addYear = 1
ElseIf monthDayComparison < 0 Then '//haven't had
birthday this year
addYear = 0
ElseIf monthDayComparison = 0 Then '// birthday today
addYear = 1
Dim timeDifference: timeDifference =
DateDiff("s", Hour(currentDate) & ":" & Minute(currentDate) & ":" &
Second(currentDate), Hour(birthDate) & ":" & Minute(birthDate) & ":" &
Second(birthDate))
If timeDifference > 0 Then: addYear = 0: End
If
End If

yearsOld = Year(currentDate) - Year(birthDate) - 1 + addYear
End Function
%>



On Sun, 4 Jan 2004 14:40:14 -0000, "Gav" <(E-Mail Removed)> wrote:

>I have a database with date of births stored dd/mm/yyyy (english dating
>system) and =date() returns a date in the same format in my server.
>
>how do i find the persons age using these two pieces of date.
>
>thanks
>gavin
>
>


 
Reply With Quote
 
Guest
Posts: n/a
 
      01-04-2004
"Do you care more about accuracy, or about tidiness of code?"

About optimal ratio between these two.
Precision has to fit the purpose.
Gav is asking about people's age, and in this case full years (or may be
full months) should suffice, unless he is doing a new baby database for a
maternity unit - then one would need not only days but hours as well.


"Aaron Bertrand [MVP]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> > Cannot this be done by converting the two dates to strings, chopping off

> dd
> > and mm, convert the rest yyyy to number and see the difference?

>
> Sure, if you want a rough guess. Do you care more about accuracy, or

about
> tidiness of code? Your code can still be tidy, you throw the logic into a
> function...
>
>



 
Reply With Quote
 
dlbjr
Guest
Posts: n/a
 
      01-04-2004
dblAge = DateDiff("d",dtmBirthDate,Date) / 365.25

-dlbjr

Discerning resolutions for the alms


 
Reply With Quote
 
Brynn
Guest
Posts: n/a
 
      01-05-2004

dblAge = Int(DateDiff("d",dtmBirthDate,Date) / 365.25)

On Sun, 4 Jan 2004 17:38:27 -0600, "dlbjr" <(E-Mail Removed)> wrote:

>dblAge = DateDiff("d",dtmBirthDate,Date) / 365.25
>
>-dlbjr
>
>Discerning resolutions for the alms
>
>


 
Reply With Quote
 
Aaron Bertrand [MVP]
Guest
Posts: n/a
 
      01-05-2004
> "Do you care more about accuracy, or about tidiness of code?"
>
> About optimal ratio between these two.
> Precision has to fit the purpose.
> Gav is asking about people's age, and in this case full years (or may be
> full months) should suffice, unless he is doing a new baby database for a
> maternity unit - then one would need not only days but hours as well.


So if you want to know if today is someone's birthday, you just need to know
that it's in the current month?

And if you want to remind someone that their friend's birthday is one week
away, it doesn't matter when you do it, as long as it is within the current
month?

If you want to know the birth MONTH, ask for that. If you want to know the
birth DAY, well, that requires accuracy to the day, not the month.

Again, the code can be as tidy as you want it, because you can stuff the
logic away in a function. Encapsulation is a pretty fundamental concept of
software engineering... and so is being accurate as opposed to "close
enough"...


 
Reply With Quote
 
Brynn
Guest
Posts: n/a
 
      01-05-2004

I certainly am not trying to argue a point ... just curious ...
what dates will give a different response from the subroutine on
aspfaqs then the following ...

<%
Funtion age(dob)
age = Int(DateDiff("d",dob, Date()) / 365.25)

'//
addToAge = DateDiff( "s", Hour(dob) & ":" & Minute(dob) & ":" &
Second(dob), Hour(Date()) & ":" & Minute(Date)) & ":" &
Second(Date()))

If addToAge =< 0 Then: age = age + 1: End if
End Function
%>

I am only asking to see if I am missing something. Not to be a
smart-arse ... my name is Brynn not Bob

Thanks in advance for your reply,

Brynn



On Sun, 4 Jan 2004 21:59:35 -0500, "Aaron Bertrand [MVP]"
<(E-Mail Removed)> wrote:

>> "Do you care more about accuracy, or about tidiness of code?"
>>
>> About optimal ratio between these two.
>> Precision has to fit the purpose.
>> Gav is asking about people's age, and in this case full years (or may be
>> full months) should suffice, unless he is doing a new baby database for a
>> maternity unit - then one would need not only days but hours as well.

>
>So if you want to know if today is someone's birthday, you just need to know
>that it's in the current month?
>
>And if you want to remind someone that their friend's birthday is one week
>away, it doesn't matter when you do it, as long as it is within the current
>month?
>
>If you want to know the birth MONTH, ask for that. If you want to know the
>birth DAY, well, that requires accuracy to the day, not the month.
>
>Again, the code can be as tidy as you want it, because you can stuff the
>logic away in a function. Encapsulation is a pretty fundamental concept of
>software engineering... and so is being accurate as opposed to "close
>enough"...
>
>


 
Reply With Quote
 
Aaron Bertrand [MVP]
Guest
Posts: n/a
 
      01-05-2004
> I certainly am not trying to argue a point ... just curious ...
> what dates will give a different response from the subroutine on
> aspfaqs then the following ...


I have no idea, I haven't tested it. I imagine there might be a problem for
leap year babies at the century that does NOT have a leap year (something
about divisible by 4, but not 400)?

A


 
Reply With Quote
 
 
 
Reply

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 Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
calculate age from date of birth TJS ASP .Net 9 09-07-2010 05:08 PM
Age to birth year eggie5 Ruby 2 09-25-2007 05:56 PM
Birth date for VHDL 87 ? Rick North VHDL 2 01-20-2007 08:24 AM
print("my name is {name}, and {age}-year old {gender}", name, age, gender); =?iso-8859-1?B?bW9vcJk=?= Java 7 01-02-2006 04:39 PM
Can cout do like printf("Name: %s, Age: %d\n",name,age)? cylin C++ 6 08-19-2003 09:03 PM



Advertisments