다음을 통해 공유


COleDateTime Class

Encapsulates the DATE data type that is used in OLE automation.

class COleDateTime

Members

Public Constructors

Name

Description

COleDateTime::COleDateTime

Constructs a COleDateTime object.

Public Methods

Name

Description

COleDateTime::Format

Generates a formatted string representation of a COleDateTime object.

COleDateTime::GetAsDBTIMESTAMP

Call this method to obtain the time in the COleDateTime object as a DBTIMESTAMP data structure.

COleDateTime::GetAsSystemTime

Call this method to obtain the time in the COleDateTime object as a SYSTEMTIME data structure.

COleDateTime::GetAsUDATE

Call this method to obtain the time in the COleDateTime as a UDATE data structure.

COleDateTime::GetCurrentTime

Creates a COleDateTime object that represents the current time (static member function).

COleDateTime::GetDay

Returns the day this COleDateTime object represents (1 – 31).

COleDateTime::GetDayOfWeek

Returns the day of the week this COleDateTime object represents (Sunday = 1).

COleDateTime::GetDayOfYear

Returns the day of the year this COleDateTime object represents (Jan 1 = 1).

COleDateTime::GetHour

Returns the hour this COleDateTime object represents (0 – 23).

COleDateTime::GetMinute

Returns the minute this COleDateTime object represents (0 – 59).

COleDateTime::GetMonth

Returns the month this COleDateTime object represents (1 – 12).

COleDateTime::GetSecond

Returns the second this COleDateTime object represents (0 – 59).

COleDateTime::GetStatus

Gets the status (validity) of this COleDateTime object.

COleDateTime::GetYear

Returns the year this COleDateTime object represents.

COleDateTime::ParseDateTime

Reads a date/time value from a string and sets the value of COleDateTime.

COleDateTime::SetDate

Sets the value of this COleDateTime object to the specified date-only value.

COleDateTime::SetDateTime

Sets the value of this COleDateTime object to the specified date/time value.

COleDateTime::SetStatus

Sets the status (validity) of this COleDateTime object.

COleDateTime::SetTime

Sets the value of this COleDateTime object to the specified time-only value.

Public Operators

Name

Description

COleDateTime::operator ==, COleDateTime::operator <, etc.

Compare two COleDateTime values.

COleDateTime::operator +, COleDateTime::operator -

Add and subtract COleDateTime values.

COleDateTime::operator +=, COleDateTime::operator -=

Add and subtract a COleDateTime value from this COleDateTime object.

COleDateTime::operator =

Copies a COleDateTime value.

COleDateTime::operator DATE, COleDateTime::operator Date*

Converts a COleDateTime value into a DATE or a DATE*.

Public Data Members

Name

Description

COleDateTime::m_dt

Contains the underlying DATE for this COleDateTime object.

COleDateTime::m_status

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

See Also

Reference

COleVariant Class

CTime Class

CTimeSpan Class

Hierarchy Chart

Other Resources

ATL/MFC Shared Classes