I have a method that calculates a person's current age in years (which I now have rewritten). Now I'd like to calculate the age in years, months and days as well.
The code looks like this after I've ported it to Delphi:
procedure CalculateAge(var nYears, nMonths, nDays: Integer; const dtBirthday, dtToday: TDateTime);
yyBd, mmBd, ddBd, yyTd, mmTd, ddTd: Word;
nY, nM, nD: Integer;
DecodeDate(dtToday, yyTd, mmTd, ddTd);
DecodeDate(dtBirthday, yyBd, mmBd, ddBd);
nY := yyTd - yyBd;
if (mmTd >= mmBd) then
nM := mmTd - mmBd
nM := 12 + mmTd - mmBd;
if (ddTd >= ddBd) then
nD := ddTd - ddBd
nD := 31 + ddTd - ddBd;
if (nM < 0) then
nM := 11;
nYears := nY;
nMonths := nM;
nDays := nD;
Could someone please tell me what is wrong with the code snipet above? Does anyone have a better solution? I'm completely stuck. I've tried almost everything.
Hope someone could help me...