Returns a TDateTime value that represents a specified Year, Month, and Day.
function EncodeDate(Year: Word; Month: Word; Day: Word): TDateTime;
TDateTime EncodeDate(Word Year, Word Month, Word Day);
SysUtils
EncodeDate returns a TDateTime value from the values specified as the Year, Month, and Day parameters.
The year must be between 1 and 9999.
Valid Month values are 1 through 12.
Valid Day values are 1 through 28, 29, 30, or 31, depending on the Month value. For example, the possible Day values for month 2 (February) are 1 through 28 or 1 through 29, depending on whether or not the Year value specifies a leap year.
If the specified values are not within range, EncodeDate raises an EConvertError exception.
C++ Examples:
/* This example uses three edit controls, a label, and a button on a form. When the button is clicked, the day, month, and year specified in the edit controls is stored in a TDateTime object. Then the TDateTime object is converted to an AnsiString that is displayed in the label. */ void __fastcall TForm1::Button1Click(TObject *Sender) { TDateTime dt; try { dt = EncodeDate((Word)StrToInt(Edit1->Text), (Word)StrToInt(Edit2->Text), (Word)StrToInt(Edit3->Text)); Label1->Caption = DateToStr(dt); } catch(...) { ShowMessage("Invalid day, month, or year."); } }
Delphi Examples:
{ This example uses three edit controls, a label, and a button on a form. When the button is clicked, the day, month, and year specified in the edit controls is stored in a TDateTime object. Then the TDateTime object is converted to an AnsiString that is displayed in the label. } procedure TForm1.Button1Click(Sender: TObject); var MyDate: TDateTime; begin MyDate := SysUtils.EncodeDate(StrToInt(Edit1.Text), StrToInt(Edit2.Text), StrToInt(Edit3.Text)); Label1.Caption := DateToStr(MyDate); end;
Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
|
What do you think about this topic? Send feedback!
|