DelphiBasics
DecodeDate
Procedure
Extracts the year, month, day values from a TDateTime var. SysUtils unit
 procedure DecodeDate(const SourceDate TDateTime; out Year, Month, Day Word);
Description
The DecodeDate procedure extracts year, month and day values from a given SourceDate TDateTime type value.
 
It stores the values in the output variables : Year, Month and Day.
Related commands
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
ReplaceTimeChange only the time part of a TDateTime variable
 Download this web site as a Windows program.




 
Example code : Add a month to a date and then extract the year, month and day values
var
  myDate : TDateTime;
  myYear, myMonth, myDay : Word;
begin
  // Set up the myDate variable to have a December 2000 value
  myDate := StrToDate('29/12/2000');

  // Now add a month to this value
  myDate := IncMonth(myDate);

  // And let us see what we get
  DecodeDate(myDate, myYear, myMonth, myDay);
  ShowMessage('myDate now = '+DateToStr(myDate));
  ShowMessage('myDay      = '+IntToStr(myDay));
  ShowMessage('myMonth    = '+IntToStr(myMonth));
  ShowMessage('myYear     = '+IntToStr(myYear));
end;
Show full unit code
  myDate now = 29/01/2001
  myDay = 29
  myMonth = 1
  myYear = 2001
 
Delphi Programming © Neil Moffatt 2002 - 2022. All rights reserved.  |  Home Page