Problem solve Get help with specific problems with your technologies, process and projects.

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
 age = dyr
 End If
End Function 

Dig Deeper on LotusScript



  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...