Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   Calcular Edad. Funcciones Today. (https://www.clubdelphi.com/foros/showthread.php?t=47393)

NSL94 27-08-2007 10:52:03

Calcular Edad. Funcciones Today.
 
HOLA QUISIERA SABER COMO PUEDO RECUPERAR LA FECHA ACTUAL CON DELPHI SUSTRAERLE UNA OTRA FECHA Y DEVOLVER UN Nº DE AÑOS.
ME HACEN FALTA PUES FUNCCIONES PARA RECUPERAR FECHA Y DAR FORMATO.

PARA ILUSTRARLO ALGO MAS NECESITO HACER ESTA MISMA COSA PERO POR DELPHI NO POR SQL YA QUE MI DELPHI ME PERMITE PONER UN :DIA_ACTUAL EN UN QUERY:
Código SQL [-]
 
size="1">(CAST (((CAST(:DIA_ACTUAL AS DATE)-LRCAMPO_FECHA_NAC)/365) AS INTEGER)) AS EDAD

GRACIAS A TODOS :)
Y FUERZA PARA LOS QUE COMO YO VUELVEN DE VACACIONES Y AUN NO LLEVAN MUY BIEN EL LEVANTARSE ANTES DE LAS 7!!!!:p

dec 27-08-2007 11:07:25

Hola,

Si buscas en estos foros sobre cómo restar o sumar fechas encontrarás información. Por ejemplo, en la unidad "DateUtils.pas" encontrarás no pocas funciones, procedimientos, variables, relacionadas con el tratamiento de fechas.

PD. Edita tu mensaje y no escribas en mayúsculas, pues en Internet algo así equivale a hablar a gritos. No se ve tu mensaje mejor porque lo escribas todo en mayúsculas, ni se lee mejor, ni se entiende mejor, sino todo lo contrario.

NSL94 27-08-2007 11:21:40

Ya ya ya...
Ni siquiera me habia dado cuenta. Esque como por "estandar" tengo que programar y reportar todos mis trabajos en maj... tengo el block maj blokeado por defecto... pero blokeado blokeado eee... con un palillo y todo!!! xD
No ahora en serio, se siente. No tengo tiempo de reescribir todo el mensage, asi que si alguien le ve maldad tan solo dire en mi defensa que no grito... hablo fuerte! :P
gracias por el Tip.

dec 27-08-2007 22:00:15

Hola,

Bueno. Pero recuerda que nada te impide editar tu mensaje. Si se te escaparon las mayúsculas sin querer todavía puedes corregirlo.

paldave 29-08-2007 03:24:50

1) Recuperas la fecha actual con Date.
2) Pasas la otra fecha a TDate con StrToDateTime.
3) Utilizas esta rutina que te he escrito:

Código Delphi [-]
procedure DateDif(Date1, Date2: TDate; var Years, Months, Days: Integer);
var a1, a2, m1, m2,d1,d2: Word;
  inter: TDate;
  b: Boolean;
label c1, c2;

begin
  b := False;
  if Date1 > Date2 then
  begin
    Inter := Date1;
    Date1 := Date2;
    Date2 := Inter;
    b := True;
  end;

  Years:=0;
  Months:=0;
  Days:=0;
  decodedate(Date1, a1, m1, d1);
  decodedate(Date2, a2, m2, d2);

c1:
  if d1then
  begin
  while d1do
  begin
    inc(Days);
    inc(d1);
  end;
  end
  else if d1>d2 then
  begin
  while d1do
  begin
     inc(Days);
     inc(d1);
  end;
  d1:=0;
  inc(m1);
  if m1=13 then
  begin
    m1:=1;
    inc(a1);
  end;
  goto c1;
  end;

c2:
  if m1then
  begin
  while m1do
  begin
    inc(Months);
    inc(m1);
  end;
  end
  else if m1>m2 then
  begin
  while m1<13 do
  begin
     inc(Months);
     inc(m1);
  end;
  m1:=1;
  inc(a1);
  goto c2;
  end;

  if a1then
  while a1do
  begin
    inc(Years);
    inc(a1);
  end;

  if b = True then
  begin
    Years := -Years;
    Months := -Months;
    Days := -Days;
  end;
end;

Que tiene como entradas los valores Date1 y Date2 con ambas fechas y devuelve en las variables Years, Months y Days los Años, Meses y Días respectivamente. Saludos.


La franja horaria es GMT +2. Ahora son las 13:53:17.

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