473,240 Members | 1,632 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,240 software developers and data experts.

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
function. And of course time zones, yada yada ....

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
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
%>
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
function. And of course time zones, yada yada ....

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


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
function. And of course time zones, yada yada ....

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



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
function. And of course time zones, yada yada ....

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

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;G-E+E=R:71E*")9;W4@87)E("(@)B!R;W5N9"AD871E9&EF9B@B9 "(L4F5Q
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.

Similar topics

12
by: Surya Kiran | last post by:
Hi all, I've written a function template. say template <class T> fn (T var) { ... } Is there any way, from within the function, can we check what type of argument we've passed on to the...
0
by: P Srinivasulu | last post by:
Hi All, Has the MBREquals function been implemented in the latest 4.1.1-alpha build. I am finding problems with that command. It says that problem is there in sql syntax. If it has been...
7
by: Petr Jakes | last post by:
I have got names of functions stored in the file. For the simplicity expect one row only with two function names: printFoo, printFOO In my code I would like to define functions and then to read...
1
by: switzerland qunatium computer | last post by:
HERE I BUILT A QUICK MATRIX TOOOK 5 MINS Body: HERE I BUILD ONE FOR YOU 1.http://en.wikipedia.org/wiki/Real-time_computing 2.http://en.wikipedia.org/wiki/Quantum_computing NOW ALL YOU NEED...
26
by: Patient Guy | last post by:
The code below shows the familiar way of restricting a function to be a method of a constructed object: function aConstructor(arg) { if (typeof(arg) == "undefined") return (null);...
8
by: Sonnich | last post by:
Hi Is the such a function like IN in delphi: if( $somechar in ) dsafsakjldg; where true is for the characters mentioned above. BR
14
by: Bryan Parkoff | last post by:
Do you know that current C++ Compiler limits to 64KB segments in source code? It is good news that Microsoft Visual C++ 2005 has expanded to 4GB segments in source code. 4GB segment is ideal for...
0
by: mkhan | last post by:
Hi, i have been having trouble how to open the 'To' Contacts list(Cc or To) (address book) of a mail message in outlook using vb.net from where the user would be able to select an email address and...
18
by: sophia | last post by:
Dear all, can any one suggest ways of implementing a backtrace function in ANSI/ standard C as given in the following link ? ...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.