Ask the Expert

Is there a LotusScript function to calculate age given a date of birth?

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 

This was first published in May 2003

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to: