COleDateTime Class
Encapsulates the DATE data type that is used in OLE automation.
class COleDateTime
Members
Public Constructors
Name |
Description |
---|---|
Constructs a COleDateTime object. |
Public Methods
Name |
Description |
---|---|
Generates a formatted string representation of a COleDateTime object. |
|
Call this method to obtain the time in the COleDateTime object as a DBTIMESTAMP data structure. |
|
Call this method to obtain the time in the COleDateTime object as a SYSTEMTIME data structure. |
|
Call this method to obtain the time in the COleDateTime as a UDATE data structure. |
|
Creates a COleDateTime object that represents the current time (static member function). |
|
Returns the day this COleDateTime object represents (1 – 31). |
|
Returns the day of the week this COleDateTime object represents (Sunday = 1). |
|
Returns the day of the year this COleDateTime object represents (Jan 1 = 1). |
|
Returns the hour this COleDateTime object represents (0 – 23). |
|
Returns the minute this COleDateTime object represents (0 – 59). |
|
Returns the month this COleDateTime object represents (1 – 12). |
|
Returns the second this COleDateTime object represents (0 – 59). |
|
Gets the status (validity) of this COleDateTime object. |
|
Returns the year this COleDateTime object represents. |
|
Reads a date/time value from a string and sets the value of COleDateTime. |
|
Sets the value of this COleDateTime object to the specified date-only value. |
|
Sets the value of this COleDateTime object to the specified date/time value. |
|
Sets the status (validity) of this COleDateTime object. |
|
Sets the value of this COleDateTime object to the specified time-only value. |
Public Operators
Name |
Description |
---|---|
Compare two COleDateTime values. |
|
Add and subtract COleDateTime values. |
|
Add and subtract a COleDateTime value from this COleDateTime object. |
|
Copies a COleDateTime value. |
|
Converts a COleDateTime value into a DATE or a DATE*. |
Public Data Members
Name |
Description |
---|---|
Contains the underlying DATE for this COleDateTime object. |
|
Contains the status of this COleDateTime object. |
Remarks
COleDateTime does not have a base class.
It is one of the possible types for the VARIANT data type of OLE automation. A COleDateTime value represents an absolute date and time value.
The DATE type is implemented as a floating-point value. Days are measured from December 30, 1899, at midnight. The following table shows some dates and their associated values:
Date |
Value |
---|---|
December 29, 1899, midnight |
-1.0 |
December 29, 1899, 6 A.M |
-1.25 |
December 30, 1899, midnight |
0.0 |
December 31, 1899, midnight |
1.0 |
January 1, 1900, 6 A.M. |
2.25 |
Warning
Note in the table above that although day values become negative before midnight on December 30, 1899, time-of-day values do not. For example, 6:00 AM is always represented by a fractional value 0.25 regardless of whether the integer representing the day is positive (after December 30, 1899) or negative (before December 30, 1899). This means that a simple floating point comparison would erroneously sort a COleDateTime representing 6:00 AM on 12/29/1899 as later than one representing 7:00 AM on the same day.
The COleDateTime class handles dates from January 1, 100, through December 31, 9999. The COleDateTime class uses the Gregorian calendar; it does not support Julian dates. COleDateTime ignores Daylight Saving Time. (See Date and Time: Automation Support.)
Note
You can use the %y format to retrieve a two-digit year only for dates starting at 1900. If you use the %y format on a date before 1900, the code generates an ASSERT failure.
This type is also used to represent date-only or time-only values. By convention, the date 0 (December 30, 1899) is used for time-only values and the time 00:00 (midnight) is used for date-only values.
If you create a COleDateTime object by using a date less than 100, the date is accepted, but subsequent calls to GetYear, GetMonth, GetDay, GetHour, GetMinute, and GetSecond fail and return -1. Previously, you could use two-digit dates, but dates must be 100 or larger in MFC 4.2 and later.
To avoid problems, specify a four-digit date. For example:
COleDateTime mytime(1996, 1, 1, 0, 0, 0);
Basic arithmetic operations for the COleDateTime values use the companion class COleDateTimeSpan. COleDateTimeSpan values define a time interval. The relationship between these classes is similar to the one between CTime and CTimeSpan.
For more information about the COleDateTime and COleDateTimeSpan classes, see the article Date and Time: Automation Support.
Requirements
**Header:**ATLComTime.h