Delphi – How does Delphi calculate TDateTime as a Float value


I am new in Delphi programming.
While going through the Data Types in Delphi I found TDateTime.

While using it in my test application I come to know that the TDateTime Object provide me a Float\Double value.

I am little curious about TDateTime How it calculate the Date Time to Double value.

Below is the example code which I had used:

  LDateTime: TDateTime;
  LFloat: Double;
   LDateTime := now;// current DateTime
   LFloat:= LDateTime; // provide me a float value   

Is it using any formula to calculate Date and Time Value from Windows?

Can anyone suggest/provide me for some more information about working of TDateTime?

Thanks in advance.

Best Solution

The float represents the number of days since 30.12.1899. So float value = 1 would be 31.12.1899, 2 = 01.01.1900 and so on. The time is saved as a fraction of the day. 0.25 = 06:00, 0.5 = 12:00, 0.75 = 18.00 ...

So the 31.12.1899 12:00 would be equal to 1.5.

This makes TDateTime really easy to work with. To get the difference in days just substract two DateTimes.

02.01.2015 - 01.01.2015 = 1

Simple as it can be. To get the difference in hours just multiply by 24.

Also have a look at the functions in Unit DateUtils. They come in handy at times.

Related Question