Incrementando um mes em uma data???
:D Galera estou querendo incrementa 1 mes em uma data.
Estou usando a linha de comando.
IncMonth(Data, 1);
Mais ele me retorna a data atual. Estou fazendo algo errado???
Desde já muito obrigado.
Estou usando a linha de comando.
IncMonth(Data, 1);
Mais ele me retorna a data atual. Estou fazendo algo errado???
Desde já muito obrigado.
Superdelphi
Curtidas 0
Respostas
Rômulo Barros
02/08/2004
Exemplo:
procedure TForm1.Button1Click(Sender: TObject); var MinhaData : TDateTime; begin MinhaData := Now; ShowMessage(DateToStr(IncMonth(MinhaData,1))); end; end.
GOSTEI 0
Emerson Nascimento
02/08/2004
supondo que [i:120a63e966]Data[/i:120a63e966] seja uma variável do tipo data:
Data := IncMonth(Data, 1);
Data := IncMonth(Data, 1);
GOSTEI 0
Paulo_amorim
02/08/2004
Olá
Só explicando...
IncMonth retorna um TDateTime com sua data incrementada...
Se vc nao fizer alguma coisa receber seu IncMonth eh a mesma coisa que vc fazer o seguinte:
A função retorna o munero somado de 1... o que vc esta fazendo eh +/- assim:
Quando na verdade vc teria que fazer ShowMessage( IntToStr(SomaNumero(i) ) );
Espero que ajude
Até+
Só explicando...
IncMonth retorna um TDateTime com sua data incrementada...
Se vc nao fizer alguma coisa receber seu IncMonth eh a mesma coisa que vc fazer o seguinte:
function SomaNumero( Num: Integer ): Integer; begin Result := Num + 1; end;
A função retorna o munero somado de 1... o que vc esta fazendo eh +/- assim:
i := 0; SomaNumero(i); ShowMessage( i );
Quando na verdade vc teria que fazer ShowMessage( IntToStr(SomaNumero(i) ) );
Espero que ajude
Até+
GOSTEI 0
Tathianam
02/08/2004
Olá!
Minha solução:
Espero ter ajudado :)
Minha solução:
function IncrementaMeses(fDataOri:TDateTime;fQtd:integer):TDateTime;
var I: integer;
ano, dia, mes: word;
begin
if fQtd = 0 then
begin
result := fDataOri;
exit;
end;
decodeDate(fDataOri,ano,mes,dia);
for I := 1 to fQtd do
begin
inc(mes);
if mes = 13 then
begin
mes := 1;
inc(ano);
end;
end;
try
result := EncodeDate(ano,mes,dia);
except // caso der errado, é porque tentou fazer 30/02, por exemplo
result := UltDataDoMes(EncodeDate(ano,mes,1));
end;
end;
function UltDataDoMes(Data: TDateTime): TDateTime;
var xAno, xMes, xDia: word;
xAtual: tdatetime;
begin
DecodeDate(Data, xAno, xMes, xDia);
Inc(xMes);
if xMes > 12 then
begin
Inc(xAno);
xMes := 1;
end;
xAtual := EncodeDate(xAno,xMes,1);
xAtual := xAtual - 1;
Result := xAtual;
end;
Espero ter ajudado :)
GOSTEI 0