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

Re: Finding Age from Date of Birth by Aaron

Aaron
Sun Jan 04 09:04:55 CST 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" <gav1290@ntlworld.com> wrote in message
news:DBVJb.916$uy5.793@newsfep1-gui.server.ntli.net...
> 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
>
>



Re: Finding Age from Date of Birth by UncleWobbly

UncleWobbly
Sun Jan 04 09:45:32 CST 2004

age = datediff("y",birthdate,now)

gives it in whole years ("y")


"Gav" <gav1290@ntlworld.com> wrote in message
news:DBVJb.916$uy5.793@newsfep1-gui.server.ntli.net...
> 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
>
>



Re: Finding Age from Date of Birth by Bob

Bob
Sun Jan 04 09:53:57 CST 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"



Re: Finding Age from Date of Birth by Evertjan

Evertjan
Sun Jan 04 13:28:33 CST 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)

Re: Finding Age from Date of Birth by Gav

Gav
Sun Jan 04 12:58:31 CST 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??





Re: Finding Age from Date of Birth by Aaron

Aaron
Sun Jan 04 13:44:38 CST 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/



Re: Finding Age from Date of Birth by aa>

aa>
Sun Jan 04 14:39:20 CST 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]" <aaron@TRASHaspfaq.com> wrote in message
news:%23wn8eSt0DHA.2752@TK2MSFTNGP09.phx.gbl...
> 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" <gav1290@ntlworld.com> wrote in message
> news:DBVJb.916$uy5.793@newsfep1-gui.server.ntli.net...
> > 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
> >
> >
>
>



Re: Finding Age from Date of Birth by Aaron

Aaron
Sun Jan 04 14:50:09 CST 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...



Re: Finding Age from Date of Birth by Gav

Gav
Sun Jan 04 15:06:21 CST 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



Re: Finding Age from Date of Birth by z

z
Sun Jan 04 15:15:43 CST 2004


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



On 04 Jan 2004 19:28:33 GMT, "Evertjan."
<exjxw.hannivoort@interxnl.net> 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)


Re: Finding Age from Date of Birth by Aaron

Aaron
Sun Jan 04 15:09:55 CST 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?



Re: Finding Age from Date of Birth by z

z
Sun Jan 04 15:18:02 CST 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."
<exjxw.hannivoort@interxnl.net> 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)


Re: Finding Age from Date of Birth by z

z
Sun Jan 04 16:43:16 CST 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" <gav1290@ntlworld.com> 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
>
>


Re: Finding Age from Date of Birth by aa>

aa>
Sun Jan 04 17:21:17 CST 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]" <aaron@TRASHaspfaq.com> wrote in message
news:OijOZTw0DHA.3140@tk2msftngp13.phx.gbl...
> > 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...
>
>



Re: Finding Age from Date of Birth by dlbjr

dlbjr
Sun Jan 04 17:38:27 CST 2004

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

-dlbjr

Discerning resolutions for the alms



Re: Finding Age from Date of Birth by z

z
Sun Jan 04 19:02:38 CST 2004


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

On Sun, 4 Jan 2004 17:38:27 -0600, "dlbjr" <dontknow@do.u> wrote:

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


Re: Finding Age from Date of Birth by Aaron

Aaron
Sun Jan 04 20:59:35 CST 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"...



Re: Finding Age from Date of Birth by z

z
Sun Jan 04 21:11:49 CST 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]"
<aaron@TRASHaspfaq.com> 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"...
>
>


Re: Finding Age from Date of Birth by Aaron

Aaron
Sun Jan 04 22:35:50 CST 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



Re: Finding Age from Date of Birth by aa>

aa>
Mon Jan 05 03:01:58 CST 2004

"So if you want to know if today is someone's birthday"

If I want to know if today is someone's birthday I will write a query to do
just this job.
Something like
WHERE dd/mm of DOB = dd/mm of TODAY

I am not argue about the correctness of your solution.
I am just trying to see what is better - one big universal tool or several
dedicated small tools


"Aaron Bertrand [MVP]" <aaron@TRASHaspfaq.com> wrote in message
news:O$0T1hz0DHA.1740@TK2MSFTNGP12.phx.gbl...
> > "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"...
>
>