This documentation is archived and is not being maintained.

COleDateTime Class 

Encapsulates the DATE data type used in OLE automation.

class COleDateTime

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, measuring days from midnight, 30 December 1899. So, midnight, 31 December 1899 is represented by 1.0. Similarly, 6 AM, 1 January 1900 is represented by 2.25, and midnight, 29 December 1899 is – 1.0. However, 6 AM, 29 December 1899 is – 1.25.


To interpret the time portion, take the absolute value of the fractional part of the number.

The COleDateTime class handles dates from 1 January 100 – 31 December 9999. COleDateTime does not support Julian dates. The Gregorian calendar is assumed to extend back in time to 1 January 100.


COleDateTime ignores Daylight Saving Time. See Date and Time: Automation Support.

This type is also used to represent date-only or time-only values. By convention, the date 0 (30 December 1899) is used for time-only values. Similarly, the time 0:00 (midnight) is used for date-only values.

If you create a COleDateTime object with a date less than 100, the date will be accepted, but subsequent calls to GetYear, GetMonth, GetDay, GetHour, GetMinute, and GetSecond will fail and return -1. Previously, you could use two-digit dates, but dates must be 100 or greater 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 represent relative time, an interval. The relation between these classes is analogous to the one between CTime and CTimeSpan.

For more information on the COleDateTime and COleDateTimeSpan classes, see the article Date and Time: Automation Support.

Header: ATLComTime.h