DelphiBasics
ReplaceTime
Procedure
Change only the time part of a TDateTime variable SysUtils unit
 procedure ReplaceTime(var DateTimeVar TDateTime; const NewTimeValue TDateTime);
Description
The ReplaceTime function updates the time part of a TDateTime variable DateTimeVar with the time part of another TDateTime value NewTimeValue without affecting the date.
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
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
 Download this web site as a Windows program.




 
Example code : Change the time without changing the date
var
  myDateTime, newTime : TDateTime;

begin
  // Set the date to 29/10/2002 at 12:34:56
  myDateTime := EncodeDateTime(2002, 10, 29, 12, 34, 56, 0);
  ShowMessage('The starting date/time = '+DateTimeToStr(myDateTime));

  // Now change the time portion without touching the date
  newTime := EncodeTime(9, 45, 52, 0);
  ReplaceTime(myDateTime, newTime);
  ShowMessage('The new date/time = '+DateTimeToStr(myDateTime));
end;
Show full unit code
  The starting date/time = 29/10/2002 12:34:56
  The new date/time = 29/10/2002 09:45:52
 
Delphi Programming © Neil Moffatt . All rights reserved.  |  Home Page