Breaks a TDateTime variable into its date/time parts DateUtils unit
 procedure DecodeDateTime(const SourceDate TDateTime; out Year, Month, Day, Hour, Min, Sec, MSec Word);
The DecodeDateTime procedure extracts year, month, day, hour, minute, second and milli-second values from a given SourceDate TDateTime type value.
It stores the values in the output variables : Year, Month, Day, Hour, Min, Sec and MSec.
Related commands
DecodeDateExtracts the year, month, day values from a TDateTime var.
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 the date and then extract the date/time individual values
  myDate : TDateTime;
  myYear, myMonth, myDay : Word;
  myHour, myMin, mySec, myMilli : Word;

  // Set up the myDate variable to have a December 2000 value
  myDate := StrToDateTime('29/12/2000 12:45:12.34');

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

  // And let us see what we get
  DecodeDateTime(myDate, myYear, myMonth, myDay,
                 myHour, myMin, mySec, myMilli);
  ShowMessage('myDate now = '+DateToStr(myDate));
  ShowMessage('myHour     = '+IntToStr(myHour));
  ShowMessage('myMin      = '+IntToStr(myMin));
  ShowMessage('mySec      = '+IntToStr(mySec));
  ShowMessage('myMilli    = '+IntToStr(myMilli));
  ShowMessage('myDay      = '+IntToStr(myDay));
  ShowMessage('myMonth    = '+IntToStr(myMonth));
  ShowMessage('myYear     = '+IntToStr(myYear));
Show full unit code
  myDate now = 29/01/2001
  myHour = 12
  myMin = 45
  mySec = 12
  myMilli = 34
  myDay = 29
  myMonth = 1
  myYear = 2001
Delphi Programming © Neil Moffatt . All rights reserved.  |  Home Page