SmartPascal
DecodeTime
Procedure
Break a TDateTime value into individual time values SysUtils unit
 procedure DecodeTime ( const SourceDateTime : TDateTime; out Hour, Min, Sec, MSec : Word ) ;
Description
The DecodeTime procedure extracts hour, minute, second and milli-second values from a given SourceDateTime TDateTime type value.
 
It stores the values in the output variables : Hour, Min, Sec and MSec.
Related commands
DecodeDate Extracts the year, month, day values from a TDateTime var.
DecodeDateTime Breaks a TDateTime variable into its date/time parts
EncodeDate Build a TDateTime value from year, month and day values
EncodeDateTime Build a TDateTime value from day and time values
EncodeTime Build a TDateTime value from hour, min, sec and msec values
RecodeDate Change only the date part of a TDateTime variable
RecodeTime Change only the time part of a TDateTime variable
ReplaceDate Change only the date part of a TDateTime variable
ReplaceTime Change only the time part of a TDateTime variable
 
Example code : Add 5 minutes to a time and then extract the new time values
// Full Unit code.
// -----------------------------------------------------------
// You must store this code in a unit called Unit1 with a form
// called Form1 that has an OnCreate event called FormCreate.
 
unit Unit1;
 
interface
 
uses
  SysUtils,   // Unit containing the DecodeTime command
  DateUtils,
  Forms, Dialogs;
 
type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  end;
 
var
  
Form1: TForm1;
 
implementation
{$R *.dfm} // Include form definitions
 
procedure TForm1.FormCreate(Sender: TObject);

var
  myDate : TDateTime;
  myHour, myMin, mySec, myMilli : Word;

begin
  // Set up the myDate variable to have a December 2000 value
  myDate := StrToDateTime('29/12/2000 12:45:12.34');

  // Now add 5 minutes to this value
  myDate := IncMinute(myDate, 5);

  // And let us see what we get
  DecodeTime(myDate, myHour, myMin, mySec, myMilli);
  ShowMessage('Time now = '+TimeToStr(myDate));
  ShowMessage('Hour     = '+IntToStr(myHour));
  ShowMessage('Minute   = '+IntToStr(myMin));
  ShowMessage('Second   = '+IntToStr(mySec));
  ShowMessage('MilliSec = '+IntToStr(myMilli));
end;
 
end.
Hide full unit code
   Time now = 12:50:12
   Hour     = 12
   Minute   = 50
   Second   = 12
   MilliSec = 34