0

I am successfuly creating to COleDateTimes, and then minusing them to create a COleDateTimeSpan. For some reason calling the GetTotalSeconds() method has suddenly started returning a huge number, which appears to be the number of seconds PLUS 10281600. I am confident this was working previously.

Here is the code I am using:

m_trace.Trace(_T(" Current time: ")+COleDateTime::GetCurrentTime().Format(_T("%H:%M:%S")));
m_trace.Trace(_T(" Time to compare: ")+vI->m_codt_lastUpdated.Format(_T("%H:%M:%S")));

COleDateTimeSpan cdts = COleDateTime::GetCurrentTime() - vI->m_codt_lastUpdated;
m_trace.Trace(_T(" Comparison result formatted: ")+cdts.Format(_T("%H:%M:%S")));

int n = (COleDateTime::GetCurrentTime() - vI->m_codt_lastUpdated).GetTotalSeconds();
CString strNumber;
strNumber.Format(_T(" Comprarison result in seconds: %d"),n);
m_trace.Trace(strNumber);

m_trace.Trace() is my tracing method. What is strange is that running Format() shows that there is no problem with the actual value the COleDateTimeSpan is holding, as can be seen by the trace result:

Current time: 11:13:53
Time to compare: 11:07:04
Comparison result formatted: 00:06:49
Comprarison result in seconds: 10282009

Don't quite know how to handle this... Any help would be greatly appreciated.

Raiden616
  • 1,545
  • 3
  • 18
  • 42
  • 1
    This is all pretty normal. Note that the offset is *exactly* divisible by the number of seconds in a day. Do keep in mind that COleDateTime stores a date, not a time. So the simple explanation is that m_codt_lastUpdated stores a date in the past. Exactly 119 days ago. You just never noticed it before because when you tested your code you always got a lastUpdated value that was recorded the same day. And your Format() calls don't show the date at all. – Hans Passant Sep 05 '14 at 11:18
  • Ah brilliant okay; I modified the format to show the date and you are correct sir. However that means the problem must lie with the setting. I am setting m_codt_lastUpdated in the class definition like this: `m_codt_lastUpdated = COleDateTime::GetCurrentTime()`.. Any reason this wouldn't be updating the date value? – Raiden616 Sep 05 '14 at 11:30
  • Ah no, I've figured it out... a subroutine was updating it from the database and it was reading the american-style date. So it was updating m_lastUpdated to be May 9th, rather than September 5th. Thanks for your help – Raiden616 Sep 05 '14 at 11:31

0 Answers0