Fórum Trabalhando com datas ! #212440
08/02/2004
0
Tiagojmilam
Curtir tópico
+ 0Posts
08/02/2004
Drakkar
Abaixo o código:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls;
type
TForm1 = class(TForm)
DateTimePicker1: TDateTimePicker;
DateTimePicker2: TDateTimePicker;
procedure DateTimePicker1Change(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
function AnoBiSexto(Ayear: Integer): Boolean;
function DiasPorMes(Ayear, AMonth: Integer): Integer;
var
Form1: TForm1;
implementation
{$R *.dfm}
function AnoBiSexto(Ayear: Integer): Boolean;
begin
Result := (AYear mod 4 = 0) and ((AYear mod 100 <> 0) or
(AYear mod 400 = 0));
end;
function 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.DateTimePicker1Change(Sender: TObject);
Var
ano, mes, dia: word;
begin
DecodeDate(DateTimePicker1.Date,ano,mes,dia);
DateTimePicker2.Date:=DateTimePicker1.Date+DiasPorMes(ano,mes);
end;
end.
Gostei + 0
08/02/2004
Marco Salles
Tres Condições Para Verificar Se o Ano é Bissexto.
function AnoBiSexto(Ayear: Integer): Boolean;
begin
Result := (AYear mod 4 = 0) and ((AYear mod 100 <> 0) or
(AYear mod 400 = 0));
end;
Eu Pergunto Porque Não ´Só´ Testar a Divisão Por Quatro :?: Existem Outros Anos Cujo Resto Da Divisão Por Quatro e Zero e Este Ano Não é Bissexto :?: Qual Seria Este Ano :?: :?:Para Mim Os Anos Bissestos São Sempre Multiplos De Quatro. 2004,2000,1996,1992,1988,1984,1980......
Sugiro Simplesmente o Teste :
function AnoBiSexto(Ayear: Integer): Boolean;
begin
if (AYear mod 4 = 0) Then
Result:=True
else
Result:=False;
end;
Gostei + 0
08/02/2004
Allen74
Para esclarecer esta sua dúvida, leia neste endereço o artigo: ´A matemática dos anos bissextos´:
[url]http://www.reniza.com/matematica/novidades/0305.htm#Artigo[/url]
Gostei + 0
09/02/2004
Tnaires
IncMonth(StrToDate(´01/01/2004´), 3) retorna ´01/04/2004´.
Existe tb uma função q retorna um valor booleano indicando se o ano é bissexto ou não:
IsLeapYear(2004) retorna true;
IsLeapYear(2005) retorna false.
Essas duas funções podem ser encontradas na unit SysUtils. Na unit DateUtils ainda possuem várias outras.
Abraços.
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)