// 年齢計算を行う
// -----------------------------------------------------------------------------
// aBirthDay: 誕生日
// aBaseDay : 基準日
// result : 満年齢
// -----------------------------------------------------------------------------
function GetAge(aBirthDay, aBaseDay: TDateTime): Integer;
var
Year1, Month1, Day1: WORD;
Year2, Month2, Day2: WORD;
dBirthDay, dBaseDay: TDateTime;
begin
dBirthDay := aBirthDay;
DecodeDate(dBirthDay, Year1, Month1, Day1);
DecodeDate(aBaseDay , Year2, Month2, Day2);
if (Month1 = 2) and (Day1 = 29) and (not IsLeapYear(Year2)) then
dBirthDay := dBirthDay + 1;
DecodeDate(dBirthDay, Year1, Month1, Day1);
result := Year2 - Year1;
dBaseDay := EncodeDate(Year2, Month1, Day1);
if dBaseDay > aBaseDay then
Dec(result);
end;
// 年齢計算を行う(民法)
// -----------------------------------------------------------------------------
// aBirthDay: 誕生日
// aBaseDay : 基準日
// result : 満年齢
// -----------------------------------------------------------------------------
function GetAgeC(aBirthDay, aBaseDay: TDateTime): Integer;
var
Year1, Month1, Day1: WORD;
Year2, Month2, Day2: WORD;
dBirthDay, dBaseDay: TDateTime;
begin
dBirthDay := aBirthDay - 1;
DecodeDate(aBaseDay , Year2, Month2, Day2);
DecodeDate(dBirthDay, Year1, Month1, Day1);
result := Year2 - Year1;
dBaseDay := EncodeDate(Year2, Month1, Day1);
if dBaseDay > aBaseDay then
Dec(result);
end;
|