Tema: fechas
Ver Mensaje Individual
  #2  
Antiguo 23-11-2004
Avatar de roman
roman roman is offline
Moderador
 
Registrado: may 2003
Ubicación: Ciudad de México
Posts: 20.269
Reputación: 10
roman Es un diamante en brutoroman Es un diamante en brutoroman Es un diamante en bruto
Cita:
Empezado por minos
si tengo el mes 2 (febrero), obtener el 28 ó 29
Pero precisamente por esto no te es suficiente el número de mes. Requieres necesariamente el año.

En Delphi7 existe la función DaysInAMonth de la unidad DateUtils. Si tu versión de Delphi no cuenta con esta función fácilmente te la puedes crear:

Código Delphi [-]
function DaysInAMonth(Year, Month: Integer): Integer;
const
  Days: array[Boolean, 1..12] of Integer = (
    (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31),
    (31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
);

begin
  Result := Days[IsLeapYear(Year), Month];
end;

IsLeapYear está en la unidad SysUtils. Si tampoco cuentas con esa también es sencilla:

Código Delphi [-]
function IsLeapYear(Year: Integer): Boolean;
begin
  Result := (Year mod 4 = 0) and ((Year mod 100 <> 0) or (Year mod 400 = 0));
end;

// Saludos
Responder Con Cita