473,240 Members | 1,632 Online

# Here is a function for finding age

Here is a function where you don't have to worry about the leap year.

You will have to still be aware of time differences between you and
the server, and correct your data before entering it into the

BUT I think that most people using this will just want to say if today
is there bday than they are their new age.

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
ElseIf monthDayComparison < 0 Then '//haven't had
birthday this year
ElseIf monthDayComparison = 0 Then '// birthday today
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
%>
Jul 19 '05 #1
3 1863
Similar to aspfaq ... didn't read your post til after ... lol

On Sun, 04 Jan 2004 22:48:38 GMT, z@z.com (Brynn) wrote:
Here is a function where you don't have to worry about the leap year.

You will have to still be aware of time differences between you and
the server, and correct your data before entering it into the

BUT I think that most people using this will just want to say if today
is there bday than they are their new age.

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
ElseIf monthDayComparison < 0 Then '//haven't had
birthday this year
ElseIf monthDayComparison = 0 Then '// birthday today
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
%>

Jul 19 '05 #2
You're working to hard! Take a look at the datediff() function in VS6 help
files. I believe that function will save you a lot of time. I've attached
a crude asp example to this post for you to play with.

God Bless,

Robert

"Brynn" <z@z.com> wrote in message
news:3f***************@news.comcast.giganews.com.. .
Here is a function where you don't have to worry about the leap year.

You will have to still be aware of time differences between you and
the server, and correct your data before entering it into the

BUT I think that most people using this will just want to say if today
is there bday than they are their new age.

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
ElseIf monthDayComparison < 0 Then '//haven't had
birthday this year
ElseIf monthDayComparison = 0 Then '// birthday today
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
%>

Jul 19 '05 #3
I was just playing around more than anything ... they were arguing it
in another thread ... aspfaq.com has a script to identify leap year
babies, but I don't think that it will come up with a different result
than ...

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

then if someone REALLY wanted to go by the time of birth for whatever
crazy reason ... they could just

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

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

I have yet to find where dividing the difference by 365.25 will not
give the correct response

Thanks for the input though Robert :)

Take Care,

Brynn
www.coolpier.com
On Sun, 4 Jan 2004 16:59:02 -0800, "Robert Suffecool"
<rm*****@hotmail.com> wrote:
You're working to hard! Take a look at the datediff() function in VS6 help
files. I believe that function will save you a lot of time. I've attached
a crude asp example to this post for you to play with.

God Bless,

Robert

"Brynn" <z@z.com> wrote in message
news:3f***************@news.comcast.giganews.com. ..
Here is a function where you don't have to worry about the leap year.

You will have to still be aware of time differences between you and
the server, and correct your data before entering it into the

BUT I think that most people using this will just want to say if today
is there bday than they are their new age.

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
ElseIf monthDayComparison < 0 Then '//haven't had
birthday this year
ElseIf monthDayComparison = 0 Then '// birthday today
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
%>

begin 666 datediff.asp
M/\$A434P^#0H\2\$5!1#X-"CQ-151!(\$Y!344](D=%3D52051/4B(@0V]N=&5N
M=#TB36EC<F]S;V9T(%9I<W5A;"!3='5D:6\@-BXP(CX-"CQ4251,13Y(;W<@
M;VQD(&%R92!Y;W4_/"]4251,13X-"CPO2\$5!1#X-"CQ"3T19/@T*#0H\)4EF
M(%)E<75E<W0N1F]R;2@B='AT1\$]"(BD@/#X@(B(@5&AE;@T*"0T*"5)E<W!O
M=65S="Y&;W)M*")T>'1\$3T(B*2QN;W<I+S,V-2PR*2 F("(@>65A<G,@;VQD
M(2(I"0T*"0T*("!E;'-E("4^#0H-"CQF;W)M(&UE=&AO9#TB<&]S="(@86-T
M:6]N/2(O9&%T961I9F8N87-P(CX-"D1/0C\@/\$E.4%54(&ED/71X=\$1/0B!S
M='EL93TB3\$5&5#H@,3!P>#L@5\$]0.B Q-G!X(B -"FYA;64]='AT1\$]"/@T*
M/\$E.4%54(&ED/7-U8FUI=#\$@<W1Y;&4](DQ%1E0Z(#(U-G!X.R!43U Z(#\$U
M<'@B('1Y<&4]<W5B;6ET('9A;'5E/5-U8FUI="!N86UE/7-U8FUI=#\$^/"]F
M;W)M/@T*/"5E;F0@:68E/@T*#0H-"@T*#0H-"@T*#0H\+T)/1%D^#0H\+TA4
%34P^#0H`
`
end

Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.