RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
SysUtils.DecodeDate Function

Returns Year, Month, and Day values for a TDateTime value.

Pascal
procedure DecodeDate(const DateTime: TDateTime; var Year: Word; var Month: Word; var Day: Word);
C++
DecodeDate(const TDateTime DateTime, Word Year, Word Month, Word Day);

SysUtils

The DecodeDate procedure breaks the value specified as the Date parameter into Year, Month, and Day values. If the given TDateTime value has a negative (BC) year, the year, month, and day return parameters are all set to zero.  

C++ Examples: 

 

/*
This example uses a button and two labels on a form. When
the user clicks the button, the current date and time are
reported in the captions of the two labels.
*/
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  Word Year, Month, Day, Hour, Min, Sec, MSec;
  TDateTime dtPresent = Now();
  DecodeDate(dtPresent, Year, Month, Day);
  Label1->Caption = AnsiString("Today is Day ") + IntToStr(Day) + AnsiString(" of Month ") + IntToStr(Month) + AnsiString(" of Year ") + IntToStr(Year);
  DecodeTime(dtPresent, Hour, Min, Sec, MSec);
  Label2->Caption = AnsiString("The time is Minute ") + IntToStr(Min) + AnsiString(" of Hour ") + IntToStr(Hour);
}

 

Delphi Examples: 

{
This example uses a button and two labels on a form. When
the user clicks the button, the current date and time are
reported in the captions of the two labels.
}
procedure TForm1.Button1Click(Sender: TObject);
var
  Present: TDateTime;
  Year, Month, Day, Hour, Min, Sec, MSec: Word;
 begin
  Present:= Now;
  SysUtils.DecodeDate(Present, Year, Month, Day);
  Label1.Caption := 'Today is Day ' + IntToStr(Day) + ' of Month '
    + IntToStr(Month) + ' of Year ' + IntToStr(Year);
  SysUtils.DecodeTime(Present, Hour, Min, Sec, MSec);
  Label2.Caption := 'The time is Minute ' + IntToStr(Min) + ' of Hour '
    + IntToStr(Hour);
end;

 

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!