Question

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?

Was it helpful?

Solution

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

So you need to do:

dtval := IncHour(dtval, 1);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top