Search code examples
delphi

How to remove the seconds from TTime without resorting to TimeToStr(const datetime:TDateTime; const formatsettings:TFormatSettings)


How can the seconds be removed from a TTime variable without resorting to the extra overhead of using TimeToStr(const datetime:TDateTime; const formatsettings:TFormatSettings) to get the TTime value without the seconds?

ie this is what I need -> HH:MM:00.

Is there some kind of math operation (like ANDing or ORing the value with something) that can be performed?


Solution

  • var
      t: TTime;
      iHour, iMin, iSec, iMSec: Word;
    
    DecodeTime(t, iHour, iMin, iSec, iMSec);
    t := EncodeTime(iHour, iMin, 0, 0);