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

 
 
Gav
Guest
Posts: n/a
 
      01-04-2004
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
 
 
 
 
Aaron Bertrand [MVP]
Guest
Posts: n/a
 
      01-04-2004
You should perform the calculation in the database (the database knows the
current date also).

Here are both VBScript and database methods:
http://www.aspfaq.com/2233

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/




"Gav" <(E-Mail Removed)> wrote in message
newsBVJb.916$(E-Mail Removed)...
> 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
 
 
 
 
UncleWobbly
Guest
Posts: n/a
 
      01-04-2004
age = datediff("y",birthdate,now)

gives it in whole years ("y")


"Gav" <(E-Mail Removed)> wrote in message
newsBVJb.916$(E-Mail Removed)...
> 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
 
Bob Barrows
Guest
Posts: n/a
 
      01-04-2004
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.

Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


 
Reply With Quote
 
Gav
Guest
Posts: n/a
 
      01-04-2004
> Here are both VBScript and database methods:
> http://www.aspfaq.com/2233


thats looks to be cool but how can i input my dd/mm/yyyy figure which is
stored in my db??




 
Reply With Quote
 
Evertjan.
Guest
Posts: n/a
 
      01-04-2004
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
 
Aaron Bertrand [MVP]
Guest
Posts: n/a
 
      01-04-2004
> thats looks to be cool but how can i input my dd/mm/yyyy figure which is
> stored in my db??


Where do you need to input it? And please stop worrying about dd/mm/yyyy.
One of the reasons I suggested doing this in the database is so that you
don't have to worry about the string representation of the date. The date
isn't actually *stored* that way in the database.

So, let's step back. What is "my db"? Access 97, SQL Server 2000, Oracle,
....?

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/


 
Reply With Quote
 
Guest
Posts: n/a
 
      01-04-2004
The thing described there is quite complecated, even takes leap years into
account.
In practice, when asking a person's age one expect to be given number of
full years.
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?
To increase the precision same might be done on mm

?

"Aaron Bertrand [MVP]" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> You should perform the calculation in the database (the database knows the
> current date also).
>
> Here are both VBScript and database methods:
> http://www.aspfaq.com/2233
>
> --
> Aaron Bertrand
> SQL Server MVP
> http://www.aspfaq.com/
>
>
>
>
> "Gav" <(E-Mail Removed)> wrote in message
> newsBVJb.916$(E-Mail Removed)...
> > 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
 
Aaron Bertrand [MVP]
Guest
Posts: n/a
 
      01-04-2004
> 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
 
Gav
Guest
Posts: n/a
 
      01-04-2004
> Where do you need to input it? And please stop worrying about dd/mm/yyyy.
> One of the reasons I suggested doing this in the database is so that you
> don't have to worry about the string representation of the date. The date
> isn't actually *stored* that way in the database.
>
> So, let's step back. What is "my db"? Access 97, SQL Server 2000,

Oracle,
> ...?


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...

my db is access 2000

btw sorry for my non technical language.

gav


 
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