views:

328

answers:

1

I have the following bit of Delphi 7 code to increment a TDateTime value by one hour. For some reason it doesn't work.

 StatusMemo.Lines.Add('prior '+DateTimeToStr(dtval));
 IncHour(dtval,1); // add an hour for DST
 StatusMemo.Lines.Add('after '+DateTimeToStr(dtval));

Contents of StatusMemo after code runs:

prior 6/24/2009 5:35:40 AM
after 6/24/2009 5:35:40 AM

It behaves like IncHour is not working. I tried using IncMinute(dtval,60), and got the same result. What am I missing?

+12  A: 

IncHour returns the incremented value, it doesn't update the passed in variable.

So you need to do:

dtval := IncHour(dtval, 1);
Jon Benedicto
Bingo. Thanks - I totally missed that it was a function, not a procedure.
tim11g
Hm, that name is unfortunate. With Integers, it's Inc(x) or x := Succ(x).
Ulrich Gerhardt
Seems RTFM before using would avoid the entire question....
Fabricio Araujo