(Q) How do I calculate the age of a person given his/her birthdate?
(A) There are several methods to do this. I'll list two methods that have been posted
to the newsgroups in the recent past:
Assuming that the birthdate field is called [BDate] and is of type date, you can use
the following calculation
Age=DateDiff("yyyy", [Bdate], Now())+ _
Int( Format(now(),
"mmdd") < Format( [Bdate], "mmdd") )
Alternate: You can use this function to calculate Age.
Function Age(Bdate, DateToday) As Integer
If Month(DateToday) < Month(Bdate) Or (Month(DateToday) = _
Month(Bdate) And Day(DateToday) < Day(Bdate)) Then
Age = Year(DateToday) -
Year(Bdate) - 1
Else
Age = Year(DateToday) -
Year(Bdate)
End If
End Function
Here's another detailed Age Checker.
Public Sub CalcAge(vDate1 As Date, vdate2 As Date, ByRef vYears As Integer,
ByRef vMonths As Integer, ByRef vDays As Integer)
vMonths = DateDiff("m", vDate1, vdate2)
vDays = DateDiff("d", DateAdd("m", vMonths, vDate1), vdate2)
If vDays < 0 Then
vMonths = vMonths - 1
vDays = DateDiff("d", DateAdd("m", vMonths, vDate1), vdate2)
End If
vYears = vMonths \ 12
vMonths = vMonths Mod 12
End Sub
|