Fórum Incrementando um mes em uma data??? #245291

02/08/2004

0

: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.


Superdelphi

Superdelphi

Responder

Posts

02/08/2004

Rômulo Barros

Exemplo:

procedure TForm1.Button1Click(Sender: TObject);
var
  MinhaData : TDateTime;
begin
  MinhaData := Now;
  ShowMessage(DateToStr(IncMonth(MinhaData,1)));
end;

end.



Responder

Gostei + 0

02/08/2004

Emerson Nascimento

supondo que [i:120a63e966]Data[/i:120a63e966] seja uma variável do tipo data:

Data := IncMonth(Data, 1);


Responder

Gostei + 0

02/08/2004

Paulo_amorim

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:

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é+


Responder

Gostei + 0

03/08/2004

Tathianam

Olá!

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 :)


Responder

Gostei + 0

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar