Share via


COleDateTime::operator +, -

Add and subtract ColeDateTime values.

COleDateTime operator +(
   COleDateTimeSpan dateSpan 
) const throw( );
COleDateTime operator -(
   COleDateTimeSpan dateSpan 
) const throw( );
COleDateTimeSpan operator -(
   const COleDateTime& date 
) const throw( );

Remarks

COleDateTime objects represent absolute times. COleDateTimeSpan objects represent relative times. The first two operators allow you to add and subtract a COleDateTimeSpan value from a COleDateTime value. The third operator allows you to subtract one COleDateTime value from another to yield a COleDateTimeSpan value.

If either of the operands is null, the status of the resulting COleDateTime value is null.

If the resulting COleDateTime value falls outside the bounds of acceptable values, the status of that COleDateTime value is invalid.

If either of the operands is invalid and the other is not null, the status of the resulting COleDateTime value is invalid.

The + and - operators will assert if the COleDateTime object is set to null. See COleDateTime Relational Operators for an example.

For more information on the valid, invalid, and null status values, see the m_status member variable.

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

Example

COleDateTime t1(1999, 3, 19, 22, 15, 0); // 10:15PM March 19, 1999
COleDateTime t2(1999, 3, 20, 22, 15, 0); // 10:15PM March 20, 1999

// Subtract 2 COleDateTimes
COleDateTimeSpan ts = t2 - t1;

// one day is 24 * 60 * 60 == 86400 seconds
ASSERT(ts.GetTotalSeconds() == 86400L);

// Add a COleDateTimeSpan to a COleDateTime.
ASSERT((t1 + ts) == t2);

// Subtract a COleDateTimeSpan from a COleDateTime.
ASSERT((t2 - ts) == t1);   

Requirements

Header: atlcomtime.h

See Also

Reference

COleDateTime Class

Hierarchy Chart

COleDateTime::operator +=, -=

COleDateTime::GetStatus

COleDateTimeSpan Class

Other Resources

COleDateTime Members