System.TDateTime
Delphi
TDateTime = type Double;
C++
class RTL_DELPHIRETURN TDateTime : public TDateTimeBase
Properties
Type | Visibility | Source | Unit | Parent |
---|---|---|---|---|
type class |
public | System.pas systdate.h |
System | System |
Description
TDateTime is the C++ analog for the Delphi TDateTime data type.
TDateTime implements the Delphi TDateTime data type and the date/time run-time library routines that use the TDateTime data type.
The TDateTime class inherits a val data member--declared as a double--that holds the date-time value. The integral part of a TDateTime value is the number of days that have passed since December 30, 1899. The fractional part of a TDateTime value is the time of day. The maximal correct date supported by TDateTime values is limited to 12/31/9999 23:59:59:999. All values that go beyond this date cause errors and exceptions in most routines that operate with TDateTime values.
TDateTime supports negative values too. You should use negative TDateTime values with care. Incorrect use of negative values can lead to various problems.
The following table displays examples of TDateTime values and their corresponding dates and times:
Value | Description |
0 | December 30, 1899; 12:00 A.M. |
2.75 | January 1, 1900; 6:00 P.M. |
-1.25 | December 29, 1899; 6:00 A.M. |
35065 | January 1, 1996; 12:00 A.M. |
To find the fractional number of days between two dates, simply subtract the two values, unless one of the TDateTime values is negative. Similarly, to increment a date and time value by a certain fractional number of days, add the fractional number to the date and time value if the TDateTime value is positive.
The DateUtils unit has several APIs (such as DaysBetween, HoursBetween, WeeksBetween, etc) that are better APIs for calculating the time between two TDateTime, and these APIs work whether the underlying double is negative or positive.
When working with negative TDateTime values, computations must handle time portion separately. The fractional part reflects the fraction of a 24-hour day without regard to the sign of the TDateTime value. For example, 6:00 A.M. on December 29, 1899 is –1.25, not –1 + 0.25, which would equal –0.75. Dates greater than -1.0 up to 0.0, and dates less than 1.0 down to 0.0, mirror each other. That's because +ve zero and -ve zero are equal.
The following stream operators are defined:
ostream& operator << (ostream& os, const TDateTime& arg);
istream& operator >> (istream& is, TDateTime& arg);