Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Trucos (https://www.clubdelphi.com/foros/forumdisplay.php?f=52)
-   -   Diferencias entre dos fechas (https://www.clubdelphi.com/foros/showthread.php?t=80670)

dec 01-07-2006 00:34:02

Diferencias entre dos fechas
 
Esta es una pequeña función para poder saber la diferencia en años, meses y dias transcurridos entre dos fechas.

Código Delphi [-]
function DifDate(FechaInicio, FechaTermino: TDateTime): String;
Var
   fYear,fMonth,fDay,iYear,iMonth,iDay,dYear,dMonth,dDay: Integer;
begin
   fYear :=Year(FechaTermino);
   fMonth:=Month(FechaTermino);
   fDay :=Day(FechaTermino);
   iYear :=Year(FechaInicio);
   iMonth:=Month(FechaInicio);
   iDay :=Day(FechaInicio);
   dYear:=fYear-iYear;

   if fMonththen
    begin
       dMonth:=fMonth+12-iMonth;
       dYear:=dYear-1;
    end
   else
    dMonth:=fMonth-iMonth;

    if fDaythen
    begin
      dMonth:=dMonth-1;
      if (fMonth-1=1) or (fMonth-1=3) or (fMonth-1=5) or (fMonth-1=7) then
         fDay:=fDay+31
      else
          if (fMonth-1=8) or (fMonth-1=10) or (fMonth-1=12) or (fMonth-1=0) then
             fDay:=fDay+31
          else
              if (fMonth-1=4) or (fMonth-1=6) or (fMonth-1=9) or (fMonth-1=11) then
                 fDay:=fDay+30
              else
                 fDay:=fDay+28;
    end;

    if dMonth<0 then
    begin
       dYear:=dYear-1;
      dMonth:=11;
    end;

    dDay:=fDay-iDay;

    Result:=IntToStr(dYear)+'/'+IntToStr(dMonth)+'/'+IntToStr(dDay);
end;


La franja horaria es GMT +2. Ahora son las 23:54:43.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi