Data type holding a date and time value System unit
  type TDateTime = type Double;
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. It really should be 31 Dec is.
It appears that the reason for Delphi starting at 30 Dec 1899 is to make it as compatible as possible with Excel while at the same time not adopting Excel's incorrectness about dates. Historically, Excel played second fiddle to Lotus 1-2-3. Lotus (which may have got this error from Visicalc) incorrectly considered 1900 to be a leap year hence a value of 60 gives you 29 Feb 1900 in Excel but is interpreted as 28 Feb 1900 in Delphi due to Delphi starting 1 day before. From the 01 Mar 1901 the two date systems give the same result for a given number.
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.
No local time information is held with TDateTime - just the day and time values.
Related commands
DateTimeToFileDate Convert a TDateTime value to a File date/time format
DateTimeToStr Converts TDateTime date and time values to a string
DateTimeToString Rich formatting of a TDateTime variable into a string
PDateTime Pointer to a TDateTime value
StrToDateTime Converts a date+time string into a TDateTime value
 Author links

 Buy Website Traffic at

 Buy Proxies at
 Download this web site as a Windows program.

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;
  // The System unit does not need to be defined
  Forms, Dialogs;
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
Form1: TForm1;
{$R *.dfm} // Include form definitions
procedure TForm1.FormCreate(Sender: TObject);

  day1, day2 : TDateTime;
  diff : Double;
  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');
Hide full unit code
   day1 = 12/06/2002
   day2 = 12/07/2002
   day2 - day1 = 30 days
Delphi Programming Neil Moffatt 2002 - 2017. All rights reserved.  |  Home Page