Code: |
{ BrthDate: Date of birth }
function TFFuncs.CalcAge(brthdate: TDateTime): Integer; var month, day, year, bmonth, bday, byear: word; begin DecodeDate(BrthDate, byear, bmonth, bday); if bmonth = 0then result := 0 else begin DecodeDate(Date, year, month, day); result := year - byear; if (100 * month + day) < (100 * bmonth + bday) then result := result - 1; end; end; |
Code: |
procedure TForm1.Button1Click(Sender: TObject); var Month, Day, Year, CurrentMonth, CurrentDay, CurrentYear: word; Age: integer; begin DecodeDate(DateTimePicker1.Date, Year, Month, Day); DecodeDate(Date, CurrentYear, CurrentMonth, CurrentDay); if (Year = CurrentYear) and (Month = CurrentMonth) and (Day = CurrentDay) then Age := 0 else begin Age := CurrentYear - Year; if (Month > CurrentMonth) then dec(Age) elseif Month = CurrentMonth then if (Day > CurrentDay) then dec(Age); end; Label1.Caption := IntToStr(Age); end; |
Взято с Delphi Knowledge Base: https://www.baltsoft
Code: |
function CalculateAge(Birthday, CurrentDate: TDate): Integer; var Month, Day, Year, CurrentYear, CurrentMonth, CurrentDay: Word; begin DecodeDate(Birthday, Year, Month, Day); DecodeDate(CurrentDate, CurrentYear, CurrentMonth, CurrentDay);
if (Year = CurrentYear) and (Month = CurrentMonth) and (Day = CurrentDay) then begin Result := 0; end else begin Result := CurrentYear - Year; if (Month > CurrentMonth) then Dec(Result) else begin if Month = CurrentMonth then if (Day > CurrentDay) then Dec(Result); end; end; end;
procedure TForm1.Button1Click(Sender: TObject); begin Label1.Caption := Format('Your age is %d', [CalculateAge(StrToDate('01.01.1903'), Date)]); end; |
Взято с сайта: https://www.swissdelphicenter.
Code: |
DecodeDate(DM.Table.FieldByName('Born').AsDateTime, Year, Month, Day); // Дата рождения DecodeDate(Date, YYYY, MM, DD); // Текущая дата
if (MM >= Month) and (DD >= Day) then Edit2.Text := IntToStr((YYYY - Year)) else Edit2.Text := IntToStr((YYYY - Year) - 1); |
https://delphiworld.narod.
Просьба писать ваши замечания, наблюдения и все остальное,
что поможет улучшить предоставляемую информацию на этом сайте.
ВСЕ КОММЕНТАРИИ МОДЕРИРУЮТСЯ ВРУЧНУЮ, ТАК ЧТО СПАМИТЬ БЕСПОЛЕЗНО!