Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

delphi

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?

like image 315
Steve F Avatar asked Jun 25 '11 04:06

Steve F


2 Answers

uses
  ..., DateUtils;

var
  t: TTime;
begin
  t := ...;
  t := RecodeSecond(t, 0);
end;
like image 88
Remy Lebeau Avatar answered Sep 22 '22 16:09

Remy Lebeau


var
  t: TTime;
  iHour, iMin, iSec, iMSec: Word;

DecodeTime(t, iHour, iMin, iSec, iMSec);
t := EncodeTime(iHour, iMin, 0, 0);
like image 28
oodesigner Avatar answered Sep 20 '22 16:09

oodesigner