Break a TDateTime value into individual time values SysUtils unit
 procedure DecodeTime(const SourceDateTime TDateTime; out Hour, Min, Sec, MSec Word);
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
DecodeDateExtracts the year, month, day values from a TDateTime var.
DecodeDateTimeBreaks a TDateTime variable into its date/time parts
EncodeDateBuild a TDateTime value from year, month and day values
EncodeDateTimeBuild a TDateTime value from day and time values
EncodeTimeBuild a TDateTime value from hour, min, sec and msec values
RecodeDateChange only the date part of a TDateTime variable
RecodeTimeChange only the time part of a TDateTime variable
ReplaceDateChange only the date part of a TDateTime variable
ReplaceTimeChange only the time part of a TDateTime variable
 Download this web site as a Windows program.

Example code : Add 5 minutes to a time and then extract the new time values
  myDate : TDateTime;
  myHour, myMin, mySec, myMilli : Word;

  // 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));
Show full unit code
  Time now = 12:50:12
  Hour = 12
  Minute = 50
  Second = 12
  MilliSec = 34
Delphi Programming © Neil Moffatt . All rights reserved.  |  Home Page