"David Lowndes" wrote:
Which function in the MFC/ATL COleDateTime sources has this ASSERT?
Can you give a minimal example of how to reproduce this behaviour in a
manner that reproduces your more complex situation with the database
(but without the database of course).
***Server side***
When I read a date from the database using ADO, and that date is NULL (very likely, e.g. no starting time has been defined) I get a VT_NULL variant.
So I use the following code (where lpFieldName is a LPCTSTR, and pRecordset is an ADO Recordset (ordinary ADO, not .NET)
_variant_t vtFld;
COleDateTime time;
vtFld = pRecordset->Fields->GetItem(lpFieldName)->Value;
switch(vtFld.vt)
{
case VT_DATE:
{
COleDateTime dt(vtFld);
time = dt;
}
break;
case VT_EMPTY:
case VT_NULL:
time.SetStatus(COleDateTime::null);
}
***Client side***
When I want to convert the COleDateTime to a DATE for a COM client, I write (of course, m_dtEstmStrtTm is a COleDateTime and dOutEstmStartTm is a DATE) :
dOutEstmStartTm = DATE(m_dtEstmStrtTm);
or simply:
dOutEstmStartTm = m_dtEstmStrtTm; // the same!
The source code for COleDateTime in 6.0 reads:
_AFXDISP_INLINE COleDateTime::operator DATE() const
{ return m_dt; }
But in 7.1 it reads:
ATLCOMTIME_INLINE COleDateTime::operator DATE() const throw()
{
ATLASSERT(GetStatus() == valid);
return( m_dt );
}
that's not documented in MSDN 2003 (at least, I didn't find anything...) !
Shall I change the server side (i.e. avoid setting the status of COleDateTime to COleDateTime::null) or the client side (i.e. return zero when the status is COleDateTime::null) ?
Is zero the same as a "null" datetime? How can my clients tell a missing date from a "zero" date? I don't want them to display "midnight, 30 December 1899"!
Thank you very much
Paolo