lundi 20 décembre 2010

Claculer l’age entre deux date


  1.  Interface :

Dans une fiche  placer :
Deux boutons un pour caption 'calculer' et  l'autre fermer.
trois label: un pour caption : 'Du' autre ' Au' autre ' Age'.

2. Programmation : 

déclarer ces deux fonction :
function Nomberofdays(const DT1, DT2: TDateTime): LongInt;
begin
   Result := Trunc (DT2) - Trunc (DT1);
End;
 function Diffa(const DT1: TDateTime; const DT2: TDateTime):string ;
var  Day1, Month1, Year1 ,Day2, Month2, Year2,IDay,IMonth,IYear: word;
begin
IYear:=0;
 DecodeDate(dt1,Year1,Month1,Day1);
 DecodeDate(dt2,Year2,Month2,Day2);
       if Year2>= Year1 then IYear := Year2 - Year1 else
           begin
           showmessage('Inversé les Dates SVP');
           abort;
           end;

      if  Month2>= Month1          then
              IMonth := Month2 - Month1 
else
            begin
               IMonth := 12 + Month2 - Month1 ;
               IYear  := IYear -1 ;
               if IYear =65535 then   //-1
                begin
                showmessage('Inversé les Dates SVP');
                abort;
                end;
            end;
       if  Day2>= Day1          then
           IDay := Day2 - Day1 else
           begin
             IDay := 30 + Day2 - Day1;
             IMonth :=  IMonth -1;
             if IMonth =65535 then
                begin
                IMonth := IMonth +12;
                IYear :=  IYear -1;
                   if  IYear = 65535  then
                     begin
                     showmessage('Inversé les Dates SVP');
                     abort;
                     end;(* *)
                  end;
           end;

Double clique sur le bouton "Claculer"  écrire :


procedure TForm1.Button2Click(Sender: TObject);
begin
 label3.Caption:=diffa(dt1.date,dt2.Date);
end;



Aucun commentaire:

Enregistrer un commentaire