Calculate Age

1. Member
Join Date
Dec 1969
Posts
85

## Calculate Age

Morning<BR><BR>I wish to be able to calculate a persons age from thier DOB but the functions I can find are not accurate enough i.e. born 07/11/1979 - the person would be 24...but that isn&#039;t strictly true until November 7th...<BR><BR>Can anyone point me in the direction of a suitable solution.<BR><BR>Cheers Matt

2. Member
Join Date
Dec 1969
Posts
81

## RE: Calculate Age

Use dateDiff("d",dtStart,now()) and divide the number of days by 365 to give a good approximation of the age.

3. Member
Join Date
Dec 1969
Posts
85

## So much simpler...totally missed it...Thanks

.

4. Senior Member
Join Date
Dec 1969
Posts
121

## RE: Calculate Age

If you divide by 365.25 your calculations will be even more accurate :P<BR><BR>Or use this:<BR><BR>&#060;% <BR> &#039; use DateSerial(y,m,d) to avoid locale issues <BR> date1 = DateSerial(1974,2,24) <BR> date2 = DateSerial(year(date), month(date), day(date)) <BR> <BR> &#039; make sure we have a valid date! <BR> if date2 &#062;= date1 then <BR> <BR> &#039; determine if leapYearBaby <BR> if month(date1) = 2 and day(date1) = 29 then <BR> leapBaby = true <BR> end if <BR> <BR> &#039; get absolute number of years <BR> ageInYears = cint(datediff("YYYY", date1, date2)) <BR> <BR> &#039; get date1&#039;s month and day in terms of date2&#039;s year <BR> date1alt = dateadd("yyyy", ageInYears, date1) <BR> <BR> <BR> if date1alt &#062; date2 then <BR> &#039; their birthday hasn&#039;t hit yet in date2&#039;s year <BR> ageInYears = ageInYears - 1 <BR> end if <BR> <BR> if leapBaby = true then <BR> &#039; need to format output slightly <BR> yearsPassed = ageInYears <BR> ageInYears = ageInYears 4 <BR> end if <BR> <BR> response.write "Age: " & ageInYears <BR> if leapBaby then response.write " (" & yearsPassed & " years since birth)" <BR> else <BR> response.write "Invalid date." <BR> end if <BR>%&#062;<BR><BR>For exactly the right age

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•