bfeddish
asked on
Adding a day not working
I have this in the declarations:
CTimeSpan tTimeSpanOneDay(1, 0 , 0 , 0) ;
Later on I have this:
CTime dNewNextPayDate(nNewYear, nNewMonth, nNewDay , 0, 0, 0) ;
tRetNextPayDate = dNewNextPayDate ;
tRetNextPayDate is equal to 10/31/2004 at this point.
When I do this:
tRetNextPayDate = tRetNextPayDate + tTimeSpanOneDay;
tRetNextPayDate still has 10/31/2004 in it.
If I create the date like this:
CTime dNewNextPayDate(nNewYear, nNewMonth, nNewDay , 12, 0, 0) ; <-- added the 12
Then the date addition yeilds the correct new date, 11/1/2004.
What's going on here?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
OK, here's what I came up with:
1) Use the MS workaround from the Knowledge Base article - you'll have to be careful about side effects on this one.
2) Use ColeDateTime/COleDateTimeS pan instead (doesn't use daylight time)
3) If you don't care about the time portion (you're just doing full day calculations) set the initial CTime time to 12:00:00. Your time will fluctuate +- 1 hour on the daylight changeovers, but the date will be correct. If you care about partial days, this will not work.
1) Use the MS workaround from the Knowledge Base article - you'll have to be careful about side effects on this one.
2) Use ColeDateTime/COleDateTimeS
3) If you don't care about the time portion (you're just doing full day calculations) set the initial CTime time to 12:00:00. Your time will fluctuate +- 1 hour on the daylight changeovers, but the date will be correct. If you care about partial days, this will not work.
CTimeSpan tTimeSpanOneDay(1, 0 , 0 , 0) ;
CTime dNewNextPayDate(2004, 10, 31 , 0, 0, 0) ;
CTime tRetNextPayDate = dNewNextPayDate ;
//tRetNextPayDate is equal to 10/31/2004 at this point.
int iD = tRetNextPayDate.GetDay();
int iy = tRetNextPayDate.GetYear();
int im = tRetNextPayDate.GetMonth()
int ih = tRetNextPayDate.GetHour();
// here iD = 31, iy=2004, im=10, ih=0
tRetNextPayDate = tRetNextPayDate + tTimeSpanOneDay;
iD = tRetNextPayDate.GetDay();
iy = tRetNextPayDate.GetYear();
im = tRetNextPayDate.GetMonth()
ih = tRetNextPayDate.GetHour();
// here iD = 1, iy=2004, im=11, ih=0
So it works on my side.