Build a TDateTime value from hour, min, sec and msec values SysUtils unit
 function EncodeTime(const Hour, Min, Sec, MSec Word):TDateTime;
The EncodeTime function generates a TDateTime return value from the passed Hour, Min, Sec and MSec (millisecond) values.
The permitted parameter values are :
Hour  = 0..23
Min  = 0..59
Sec  = 0..59
MSec  = 0..999

If you exceed these values, an EConvertError is raised.
The Date value for the TDateTime is always set to 30 Dec 1899. Quite why is not clear - it is 2 days before the start of the 20th century.
Related commands
DecodeDateExtracts the year, month, day values from a TDateTime var.
DecodeDateTimeBreaks a TDateTime variable into its date/time parts
DecodeTimeBreak a TDateTime value into individual time values
EncodeDateBuild a TDateTime value from year, month and day values
EncodeDateTimeBuild a TDateTime value from day and time values
 Download this web site as a Windows program.

Example code : Assign a time to a TDateTime variable
  myDate : TDateTime;

  // Set my date variable using the EncodeTime function
  myDate := EncodeTime(12, 34, 56, 789);

  LongTimeFormat := 'hh:mm:ss.z';  // Ensure that MSecs are shown

  ShowMessage('Date set to '+DateToStr(myDate));
  ShowMessage('Time set to '+TimeToStr(myDate));
Show full unit code
  Date set to 30/12/1899
  Time set to 12:34:56.789
Delphi Programming © Neil Moffatt . All rights reserved.  |  Home Page