tim11g
tim11g

Reputation: 1983

IncHour procedure in DateUtils

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?

Upvotes: 1

Views: 3220

Answers (1)

Jon Benedicto
Jon Benedicto

Reputation: 10582

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

So you need to do:

dtval := IncHour(dtval, 1);

Upvotes: 13

Related Questions