![]() |
|
|
+ Search |
![]()
|
Jan 15th, 2002 01:10
Anton Channing, jim m, Scott Fleming, Dave Wooldridge,
>The following example should work better...
>
>dtDOB = Request.Form("DOB")
>
>iAge = CInt(DateDiff("yyyy",FormatDateTime(dtDOB,1),Date()))
>dtTmp = CDate((Day(dtDOB) & "/" & Month(dtDOB) & "/" & Year(Date())))
>if (dtTmp => Date) then iAge = iAge - 1
>
>Response.Write "Age is " & iAge
I hate to reply to myself, but I left a bug in
the above code. This will display the wrong age
if someones birthday is today. Below is the corrected
version, tidied up and put in a neat little
function...
function getAge(dtDOB)
dim iAge, dtTmp, dtToday
dtToday = Date()
iAge = CInt(DateDiff("yyyy",FormatDateTime(dtDOB,1),Date()))
dtTmp = CDate((Day(dtDOB) & "/" & Month(dtDOB) & "/" & Year(Date
())))
if (dtTmp > Date) then iAge = iAge - 1
getAge = iAge
end function
dim DOB
DOB = "15/01/1974"
Response.Write " 1. DoB is " & DOB
Response.Write " <BR>2. Age is " & getAge(DOB)
© 1999-2004 Synop Pty Ltd