AgeAtDate Function
Returns the Age (in years) of a "person" given their Date of Birth (DOB) and the Date of Reference (DT).

Unit
QESBPCSDateTime

Declaration
Function AgeAtDate(const DOB, DT: TDateTime): Integer;

Description
If DT occurs before DB then -1 is returned.

Parameters
DOB Date of Birth.
DT Date in question.

Returns
Age in Integral Years at the Date in question.

Category
Date/Time Arithmetic Routines
Year Based Arithmetic Routines

Implementation

function AgeAtDate (const DOB, DT: TDateTime): Integer;
var
     D1, M1, Y1, D2, M2, Y2: Integer;
begin
     if DT < DOB then
          Result := -1
     else
     begin
          OptDecodeDateI (DOB, Y1, M1, D1);
          OptDecodeDateI (DT, Y2, M2, D2);
          Result := Y2 - Y1;
          if (M2 < M1) or ((M2 = M1) and (D2 < D1)) then
               Dec (Result);
     end;
End;


HTML generated by Time2HELP
http://www.time2help.com