Arsip: Menghitung Umur berapa Tahun Bulan Hari

 
user image
more 13 years ago

iccang

ada yang tau untuk hitung umur berapa tahun .... bulan.... hari
user image
more 13 years ago

ebta

Answer 1:
{ 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 = 0 then
    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;
Tip by John Boren Answer 2:
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)
    else
      if Month = CurrentMonth then
        if (Day > CurrentDay) then
          dec(Age);
  end;
  Label1.Caption := IntToStr(Age);
end;
Tip by Jon Scott
user image
more 13 years ago

ebta

Answer 1:
{ 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 = 0 then
    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;
Tip by John Boren Answer 2:
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)
    else
      if Month = CurrentMonth then
        if (Day > CurrentDay) then
          dec(Age);
  end;
  Label1.Caption := IntToStr(Age);
end;
Tip by Jon Scott
user image
more 13 years ago

ebta

wah double posting.. dan sudah terpublish lagi, padahal bukan tidak jadi di posting tolong di hapus saja pak Mod, tadi nyoba-nyoba preview kok error terus forumnya..
user image
more 13 years ago

ebta

Revisi.. coba menggunakan prosedur berikut :
procedure CariUmur(tglLahir:TDate; out tahun, bulan, hari:word);
begin
  tahun:=YearsBetween(today, tglLahir);
  if (DayOf(today) = DayOf(tglLahir)) and (MonthOf(today) = MonthOf(tglLahir))
    and (YearOf(tglLahir) <> YearOf(today)) then
    inc(tahun);
  tglLahir:=IncYear(tglLahir, tahun);
  bulan:=MonthsBetween(today, tglLahir);
  tglLahir:=IncMonth(tglLahir, bulan);
  hari:=DaysBetween(today, tglLahir);
end;
more ...
  • Pages:
  • 1
Share to
Local Business Directory, Search Engine Submission & SEO Tools FreeWebSubmission.com SonicRun.com