I would like to add seconds to a TDateTime
variable, so that the result is the top of the minute. For example, if it's 08:30:25, I want change the TDateTime
variable to store 08:31:00.
I see that TDateTime
has a Decode function, which I could use. There isn't, however, an encode function to put the altered time back into a TDateTime variable.
Using DateUtils
it's possible to do it like this:
Uses
DateUtils;
var
Seconds : Word;
Seconds := SecondOfTheMinute(MyTime); // Seconds from last whole minute
// Seconds := SecondOf(MyTime); is equivalent to SecondOfTheMinute()
if (Seconds > 0) then
MyTime := IncSecond(MyTime,60 - Seconds);
There sure is, at least in the recent versions - see the DateUtils unit, especially all the Recode*
routines and EncodeDateTime
. The DateUtils
unit is already available in Delphi 2010, perhaps even in earlier version.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With