The RecodeTime function selectively replaces the time portions of a specified TDateTime value.

The function converts the date/time TDateTime value specified by AValue, with the value obtained by changing the hour to AHour, the minute to AMinute, the second to ASecond, and the milliseconds to AMilliSecond.

  • Valid accepted values for AHour range from 0 to 24. If AHour is 24, then the values for the minutes, seconds, and milliseconds must all equal zero (0).

  • AMinute can be a value that ranges from 0 through 59 inclusive.

  • ASecond can be a value that ranges from 0 through to 59 inclusive.

  • AMilliSecond can range from 0 to 999 inclusive.

If the values provided by any of these parameters does not represent a valid time, then RecodeTime raises an exception error.

Declaration: Function RecodeTime(const AValue: TDateTime; const AHour, AMinute, ASecond, AMilliSecond: Word): TDateTime;

An example would be as follows.

procedure OnMapEvent(var Value:Variant);
var
ThatDate, TheDate : TDateTime;
aHour, aMin, aSec, aMil : word;
begin
aHour := 16;
aMin := 30;
aSec := 30;
aMil := 500;
TheDate := EncodeDateTime(2024, 06, 25, 00, 00, 00, 000);
ThatDate := RecodeTime(TheDate, aHour, aMin, aSec, aMil);
LogInfo(FormatDateTime('dd-mm-yyyy hh:nn:ss.zzz', ThatDate));
 
//This will produce an error
aHour := 16;
aMin := 70;
aSec := 30;
aMil := 500;
ThatDate := RecodeTime(TheDate, aHour, aMin, aSec, aMil);
LogInfo(FormatDateTime('dd-mm-yyyy hh:nn:ss.zzz', ThatDate));
LogInfo('');
 
end;