System.TDateTime

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

type TDateTime = { built-in type };

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. The negative spectrum mirrors the positive one exactly. As such, a value of Now (positive) is exactly the same as its negative value--Now. 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.

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. There are no TDateTime values from –1 through 0.

Note: Use only the operators declared by TDateTime. The compiler ignores any operators you overload yourself.

Warning: It is not possible to use TDateTime as a base class for inheriting. To add functionality to TDateTime, you must write a wrapper class.

Note: To utilize the C++ streaming operators (<< and >>) with Currency, you must include the iostream library before systdate library.


The following stream operators are defined:

ostream& operator << (ostream& os, const TDateTime& arg);
istream& operator >> (istream& is, TDateTime& arg);

See Also