2004. január 7., szerda

How to calculate the approximate date of birth given the age


Problem/Question/Abstract:

How to calculate the approximate date of birth given the age

Answer:

function TFFuncs.CalcDateFromAge(Age: Integer): TDateTime;
var
  month, day, year, bmonth, bday, byear: word;
  CalcString: string;
begin
  DecodeDate(Date, byear, bmonth, bday);
  byear := byear - Age;
  if (100 * month + day) < (100 * bmonth + bday) then
    byear := byear - 1;
  CalcString := Copy(IntToStr(BMonth), 1, 2) + '/';
  CalcString := CalcString + Copy(IntToStr(BDay), 1, 2) + '/';
  CalcString := CalcString + Copy(IntToStr(BYear), 1, 4);
  Result := StrToDate(CalcString);
end;

Nincsenek megjegyzések:

Megjegyzés küldése