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