Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
There are several ways, depending on the data type you want to add. COleDateTime just encapsulates the DATE type, which is simply a double. The fractional part holds time, and the integral part holds days. Thus, you could simply add a day by doing something like this:
COleDateTime dt(2002, 11, 4, 0, 0, 0);
dt.m_dt += 1; //day becomes the 5th
The m_dt member is the double value itself, so you can add and subtract days from it just by using integers. Although it is the most efficient way, it is not the "official" way ;)A more sophisticated way, and one which allows modifying the time parts too, is to use the overloaded += operator. It takes a COleDateTimeSpan object, which holds a range of days+time. The other overloaded operators (+,-,-=,=) also use that type. For example (extending the previous code):
COleDateTimeSpan span(1); //1 day//or in days/hours/min/secs...
//COleDateTimeSpan span(1,0,0,0);int iDay = dt.GetDay(); //currently 5
dt += span;
iDay = dt.GetDay(); //now 6
Cheers

![]() |
Why can't I use boolean d...
|
VB apps and Freezing
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |