Click here to Skip to main content
11,921,491 members (62,389 online)
Rate this:
Please Sign up or sign in to vote.
See more: C++ MFC
I have the huge problem with COleDateTime and CTime.
That's like a hell, and I can't understand it. I try to initialize COleDateTime by value of CTime

void CAnnouncementScheduleTab::ConvertToDateTime(COleDateTime & oleDate, CTime &time, CTime &date)
    oleDate.SetDateTime(date.GetYear(), date.GetMonth(), date.GetDay(),
        time.GetHour(), time.GetMinute(), time.GetSecond());
    int a = date.GetYear();
    int b = date.GetMonth();
    int c = date.GetDay();
    int d = time.GetHour() ;
    int e = time.GetMinute();
    int f = time.GetSecond();
    int y = oleDate.GetYear();
    int h = oleDate.GetMonth();
    int m = oleDate.GetDay();
    int o = oleDate.GetHour();
    int l = oleDate.GetMinute();
    int p = oleDate.GetSecond();
    ASSERT(a == y && b == h
        && c == m && d == o &&
        e == l && f == p);

How can you see time and date variables is OK! and a - f is normal values, but y-p is -1.
Why Am I getting it?
Before this method I did default constructor and sometimes I got bad values like a couple minutes more or less then I expected.
Thank you
Posted 20-May-13 4:39am
Edited 10-Jun-13 5:55am
Richard MacCutchan 20-May-13 10:53am
You should check the return code of the call to oleDate.SetDateTime. You are assuming that it succeeds which is not the best way of writing code. Use your debugger to step through the code and check the values at each step.
thomas_wingfield 20-May-13 11:47am
Hello Richard!Thanks for reply
I researched that if I would be initialize in constructor Current Time and after that give new values it will be ok
but I have another trouble. every time I get one-two minutes more or less.
Did you hear about it?I give correct value, but received 1-2 minutes more then I expect
Richard MacCutchan 20-May-13 13:12pm
Sorry, I have not used these classes. I can only repeat my previous advice that you use your debugger to see what is going on. However, looking at the COleDateTime documentation I notice that it uses the fractional part of a floating point number to hold the time portion, which may account for the loss of precision.
nv3 10-Jun-13 11:32am
Your code DID run correctly in my test environment. I would like to suggest that you do a test run with two known values for time and date and show what exactly you get for the variables a ...p and the double value that is used in COleDateTime. So we could reproduce your test case.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

it looks like the oledate isnt valid.

Hint: it is a input parameter in your function, so make a valid oledate before you call your function.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

That's was a problem with memory, zombie pointer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 553
1 Dave Kreskowiak 245
2 phil.o 160
3 KrunalRohit 134
4 Sergey Alexandrovich Kryukov 132
0 OriginalGriff 6,951
1 KrunalRohit 4,530
2 Sergey Alexandrovich Kryukov 3,171
3 George Jonsson 2,840
4 Suvendu Shekhar Giri 2,181

Advertise | Privacy | Mobile
Web02 | 2.8.151120.1 | Last Updated 26 Jun 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100