Is there any function to calculate the age by the given date of birth. Is there a date interval, dateadd, datesub etc. function in LotusScript as there is in VB Script?
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
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.