DelphiBasics
ReplaceDate
Procedure
Change only the date part of a TDateTime variable SysUtils unit
 procedure ReplaceDate ( var DateTimeVar : TDateTime; const NewDateValue : TDateTime ) ;
Description
The ReplaceDate function updates the date part of a TDateTime variable DateTimeVar with the date part of another TDateTime value NewDateValue without affecting the time.
Related commands
DecodeDate Extracts the year, month, day values from a TDateTime var.
DecodeDateTime Breaks a TDateTime variable into its date/time parts
DecodeTime Break a TDateTime value into individual time values
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
ReplaceTime Change only the time part of a TDateTime variable
 Author links

 Buy Website Traffic at
 Buywebsitetrafficexperts.com

 Buy Proxies at
 Buyproxies.io
 
 Download this web site as a Windows program.


 
Example code : Change the date without changing the time
var
  myDateTime, newDate : 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 date portion without touching the time
  newDate := EncodeDate(1957, 02, 18);
  ReplaceDate(myDateTime, newDate);
  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      = 18/02/1957 12:34:56
 
Delphi Programming Neil Moffatt 2002 - 2016. All rights reserved.  |  Home Page