Description |
The TDateTime type holds a date and time value.
It is stored as a Double variable, with the date as the integral part, and time as fractional part. The date is stored as the number of days since 30 Dec 1899. Quite why it is not 31 Dec is not clear. 01 Jan 1900 has a days value of 2.
Because TDateTime is actually a double, you can perform calculations on it as if it were a number. This is useful for calculations such as the difference between two dates.
|
|
Notes |
No local time information is held with TDateTime - just the day and time values.
|
|
Related commands |
|
|
|
Example code : Finding the difference between two dates |
// 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 // The System unit does not need to be defined 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
day1, day2 : TDateTime;
diff : Double;
begin
day1 := StrToDate('12/06/2002');
day2 := StrToDate('12/07/2002');
ShowMessage('day1 = '+DateToStr(day1));
ShowMessage('day2 = '+DateToStr(day2));
diff := day2 - day1;
ShowMessage('day2 - day1 = '+FloatToStr(diff)+' days');
end; end.
|
Hide full unit code |
day1 = 12/06/2002
day2 = 12/07/2002
day2 - day1 = 30 days
|
|