Description |
The EncodeDateTime function generates a TDateTime return value from the passed Year, Month, Day, Hour, Min, Sec and MSec (millisecond) values.
The permitted parameter values are :
Year | = 0..9999 |
Month | = 1..12 |
Day | = 1..31 (depending on month/year) |
| |
Hour | = 0..23 |
Min | = 0..59 |
Sec | = 0..59 |
MSec | = 0..999 |
If you exceed these values, an EConvertError is raised.
|
|
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 |
EncodeTime |
|
Build a TDateTime value from hour, min, sec and msec values |
|
|
|
Example code : Assign a full day and time value to a TDateTime variable |
// Full Unit code. // ----------------------------------------------------------- // You must store this code in a unit called Unit1 with a form // called Form1 that has an OnCreate event called FormCreate. unit Unit1; interface uses DateUtils, // Unit containing the EncodeDateTime command SysUtils, Forms, Dialogs; type TForm1 = class(TForm) procedure FormCreate(Sender: TObject); end; var Form1: TForm1; implementation {$R *.dfm} // Include form definitions procedure TForm1.FormCreate(Sender: TObject); var
myDate : TDateTime;
begin // Set my date variable using the EncodeDateTime function
myDate := EncodeDateTime(2000, 02, 29, 12, 34, 56, 789);
LongTimeFormat := 'hh:mm:ss.z'; // Ensure that MSecs are shown
ShowMessage('Date set to '+DateToStr(myDate));
ShowMessage('Time set to '+TimeToStr(myDate));
end; end.
|
Hide full unit code |
Date set to 29/02/2000
Time set to 12:34:56.789
|
|