Shared Visual C++ Classes Reference 
COleDateTime::COleDateTime 

Constructs a COleDateTime object.

COleDateTime( ) throw( ); 
COleDateTime(
   const VARIANT& varSrc 
) throw( );
COleDateTime(
   DATE dtSrc 
) throw( );
COleDateTime(
   time_t timeSrc 
) throw( );
COleDateTime(
   __time64_t timeSrc 
) throw( );
COleDateTime(
   const SYSTEMTIME& systimeSrc 
) throw( );
COleDateTime(
   const FILETIME& filetimeSrc 
) throw( );
COleDateTime(
   int nYear,
   int nMonth,
   int nDay,
   int nHour,
   int nMin,
   int nSec 
) throw( );
COleDateTime(
   WORD wDosDate,
   WORD wDosTime 
) throw( );
COleDateTime(
      const DBTIMESTAMP& dbts
) throw();

Parameters

dateSrc

An existing COleDateTime object to be copied into the new COleDateTime object.

varSrc

An existing VARIANT data structure (possibly a COleVariant object) to be converted to a date/time value (VT_DATE) and copied into the new COleDateTime object.

dtSrc

A date/time (DATE) value to be copied into the new COleDateTime object.

timeSrc

A time_t or __time64_t value to be converted to a date/time value and copied into the new COleDateTime object.

systimeSrc

A SYSTEMTIME structure to be converted to a date/time value and copied into the new COleDateTime object.

filetimeSrc

A FILETIME structure to be converted to a date/time value and copied into the new COleDateTime object. Note that FILETIME uses Universal Coordinated Time (UTC), so if you pass a local time in the structure, your results will be incorrect. See File Times in the Platform SDK for more information.

nYear, nMonth, nDay, nHour, nMin, nSec

Indicate the date and time values to be copied into the new COleDateTime object.

wDosDate, wDosTime

MS-DOS date and time values to be converted to a date/time value and copied into the new COleDateTime object.

dbts

A reference to a DBTIMESTAMP structure containing the current local time.

Remarks

All these constructors create new COleDateTime objects initialized to the specified value. The following table shows valid ranges for each date and time component:

Date/time component Valid range

year

100 – 9999

month

0 – 12

day

0 – 31

hour

0 – 23

minute

0 – 59

second

0 – 59

Note that the actual upper bound for the day component varies based on the month and year components. For details, see the SetDate or SetDateTime member functions.

Following is a brief description of each constructor:

  • COleDateTime( )   Constructs a COleDateTime object initialized to 0 (midnight, 30 December 1899).

  • COleDateTime( dateSrc )   Constructs a COleDateTime object from an existing COleDateTime object.

  • COleDateTime( varSrc )   Constructs a COleDateTime object. Attempts to convert a VARIANT structure or COleVariant object to a date/time (VT_DATE) value. If this conversion is successful, the converted value is copied into the new COleDateTime object. If it is not, the value of the COleDateTime object is set to 0 (midnight, 30 December 1899) and its status to invalid.

  • COleDateTime( dtSrc )   Constructs a COleDateTime object from a DATE value.

  • COleDateTime( timeSrc )   Constructs a COleDateTime object from a time_t value.

  • COleDateTime( systimeSrc )   Constructs a COleDateTime object from a SYSTEMTIME value.

  • COleDateTime( filetimeSrc )   Constructs a COleDateTime object from a FILETIME value. . Note that FILETIME uses Universal Coordinated Time (UTC), so if you pass a local time in the structure, your results will be incorrect. See File Times in the Platform SDK for more information.

  • COleDateTime( nYear, nMonth, nDay, nHour, nMin, nSec )   Constructs a COleDateTime object from the specified numerical values.

  • COleDateTime( wDosDate, wDosTime )   Constructs a COleDateTime object from the specified MS-DOS date and time values.

For more information, see the VARIANT entry in the Platform SDK.

For more information on the time_t data type, see the time function in the Run-Time Library Reference.

For more information, see the SYSTEMTIME and FILETIME structures in the Platform SDK.

For more information on MS-DOS date and time values, see DosDateTimeToVariantTime in the Platform SDK.

For more information about the bounds for COleDateTime values, see the article Date and Time: Automation Support.

NoteNote

The constructor using DBTIMESTAMP parameter is only available when OLEDB.h is included.

Example

time_t osBinaryTime;   // C run-time time (defined in <time.h>)
time(&osBinaryTime);   // Get the current time from the 
                     // operating system.

COleDateTime time1;   // initialized to 00:00am, 30 December 1899
                     // (and m_nStatus is valid!)

COleDateTime time2 = time1; // Copy constructor
COleDateTime time3(osBinaryTime)   // from time_t
COleDateTime time4( 1999, 3, 19, 22, 15, 0 ); // 10:15PM March 19, 1999

SYSTEMTIME sysTime;   // Win32 time information
GetSystemTime(&sysTime);

COleDateTime time5(sysTime); 

For another example, see the ShowImage Sample.

See Also

Reference

COleDateTime Class
Hierarchy Chart
COleDateTime::SetDate
COleDateTime::SetDateTime
COleDateTime::SetTime
COleDateTime::GetStatus
COleDateTime::operator =
COleDateTime::m_dt
COleDateTime::m_status

Other Resources

COleDateTime Members

Tags :


Community Content

Ben Anderson MSFT
DATETIME conversion info

As with COleDateTime::operator=(FILETIME), The description for the FILETIME copy constructor is somewhat confusing as to what sorts of conversions go on.  Here's a summary of how the copy constructor for FILETIME structures works:

FILETIME is in UTC, so the copy constructor for FILETIME (and also the FILETIME operator=), depending on the version of Visual Studio will either convert from UTC to local time, or not.  Here is a quick summary of which versions do what:

VS6: always converts to local time
VS.NET (7): initial release does not convert.  SP2 and above do convert
VS2003 .NET (7.1): initial relase does not convert SP1 will
VS2005 (8.0): always converts to local time

 

So, for most up to date versions of VS, converting to COleDateTime from FILETIME will result in two different times, since the COleDateTime copy constructor and operator= will assume that the FILETIME structure is in UTC and you want your COleDateTime class to be the same time, but in your local time (hence it will read a different time depending on what timezone you're in).

Tags :

Thomas Lee
Valid month and day values
Contrary to what is said in the table above, 0 is not a valid value for the month or the year (at least when passed to the 6-parameter constructor). The following causes an assertion:

COleDateTime(1978, 0, 29, 12, 00, 00);



Page view tracker