terça-feira, 31 de agosto de 2010

Como saber quantos dias tem no mes

function TForm1.AnoBiSexto(Ayear: Integer): Boolean;
begin
    // Verifica se o ano é Bi-Sexto
    Result := (AYear mod 4 = 0) and ((AYear mod 100 <> 0) or
    (AYear mod 400 = 0));
end;
 
function TForm1.DiasPorMes(Ayear, AMonth: Integer): Integer;
const DaysInMonth: array[1..12] of Integer = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
begin
    Result := DaysInMonth[AMonth];
    if (AMonth = 2) and AnoBiSexto(AYear) then
    Inc(Result);
end;
 
procedure TForm1.Button1Click(Sender: TObject);
begin
    Label1.Caption := IntToStr(DiasPorMes(1999, 10));
end;

Nenhum comentário:

Postar um comentário