Appearance
YearsBetween
Declaration
Function YearsBetween(const ANow: TDateTime; const AThen: TDateTime): Integer
Example
pascal
procedure OnMapEvent(var Value:Variant);
begin
// test two dates that are 27 months apart ...
Value := YearsBetween(Date, IncMonth(Date, 27)); // result is 2 (whole years, approximately)
end;Description
Returns the approximate number of years between two specified TDateTime values. Because years are not all the same length (e.g. leap years), YearsBetween returns an approximation based on an assumption of 365.25 days per year. Fractional years are not counted. Thus, for example, YearsBetween reports the difference between Jan 1 and Dec 31 as 0 on non-leap years and 1 on leap years.
The ordering of the two dates doesn't matter - the number of years will not be negative.