Compartir a través de


COleDateTime::SetDate

Sets the date of this COleDateTime object.

int SetDate(
   int nYear,
   int nMonth,
   int nDay 
) throw( );

Parameters

  • nYear, nMonth, nDay
    Indicate the date components to be copied into this COleDateTime object.

Return Value

Zero if the value of this COleDateTime object was set successfully; otherwise, 1. This return value is based on the DateTimeStatus enumerated type. For more information, see the SetStatus member function.

Remarks

The date is set to the specified values. The time is set to time 0, midnight.

See the following table for bounds for the parameter values:

Parameter

Bounds

nYear

100 – 9999

nMonth

1 – 12

nDay

0 – 31

If the day of the month overflows, it is converted to the correct day of the next month and the month and/or year is incremented accordingly. A day value of zero indicates the last day of the previous month. The behavior is the same as SystemTimeToVariantTime.

If the date value specified by the parameters is not valid, the status of this object is set to COleDateTime::invalid. You should use GetStatus to check the validity of the DATE value and should not assume that the value of m_dt will remain unmodified.

Here are some examples of date values:

nYear

nMonth

nDay

Value

2000

2

29

29 February 2000

1776

7

4

4 July 1776

1925

4

35

35 April 1925 (invalid date)

10000

1

1

1 January 10000 (invalid date)

To set both date and time, see COleDateTime::SetDateTime.

For information on member functions that query the value of this COleDateTime object, see the following member functions:

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

Example

// set only the date, time set to midnight
dt.SetDate(1999, 3, 19);
ASSERT(dt.GetYear() == 1999);
ASSERT(dt.GetDay() == 19);
ASSERT(dt.GetMonth() == 3);
ASSERT(dt.GetHour() == 0);
ASSERT(dt.GetMinute() == 0);
ASSERT(dt.GetSecond() == 0);

// setting the time only resets the date to 1899!
dt.SetTime(22, 15, 0);
ASSERT(dt.GetYear() == 1899);
ASSERT(dt.GetDay() == 30);
ASSERT(dt.GetMonth() == 12);
ASSERT(dt.GetHour() == 22);
ASSERT(dt.GetMinute() == 15);
ASSERT(dt.GetSecond() == 0);   

Requirements

Header: atlcomtime.h

See Also

Reference

COleDateTime Class

Hierarchy Chart

COleDateTime::COleDateTime

COleDateTime::SetDateTime

COleDateTime::operator =

COleDateTime::GetStatus

COleDateTime::m_dt

Other Resources

COleDateTime Members