In LotusScript there are two ways to represent dates -- using a date/time variant or a NotesDateTime object. Both types support a "subtract" operation. With the date/time variant, this is the "-" operator, such as:
daysOld = doc.DateOfBirth(0) - Today ' returns their age in days.
With NotesDateTime objects you can use TimeDifferenceDouble or TimeDifference.
However, knowing the person's age in days doesn't automatically tell you their age in years, because not all years have the same number of days. The following function determines the age by checking whether their birthday has already occurred this year. The function comes from the Notes Design Library which you can download from LDD Sandbox.
Function age(dob, asofdate) ' the arguments are assumed to be of type LotusScript date/time. Dim dyr%, dmo% dyr = Year(asofdate) - Year(dob) dmo = Month(asofdate) - Month(dob) If dmo < 0 Or (dmo = 0 And Day(asofdate) < Day(dob)) Then ' their birthday has not yet arrived this year. age = dyr - 1 Else age = dyr End If End Function
This was first published in May 2003