Converting C++ Date type to SQL DateTIme

Sorry to bother. But I need to find out a way to convert a C++
Date type to SQL DATETIME type in C++. I'm using ADO to add
information to a table.
I'm using the following code to add information to a field

m_BUNIT is a CSTRING and BUNIT is a Char type.
But I am having a tough time adding values to a DT type.

Appreciate your help.
Who is Participating?
abancroftConnect With a Mentor Commented:
CDateTime, Date, COleDateTime are not C++ structures - they are Win32/MFC (this is the C++ forum).

Have you tried using the COleVariant?


COleDateTime theDate;
COleVariant olevDate;

// Setup theDate

olevDate = theDate;
m_pRs->Fields->get_Item("a field")->get_Value(olevDate.Detach());
Which C++ date type are you using?

By "DateTime" I assume you mean adDBTimeStamp?
rianAuthor Commented:
I have use CDateTime, COleDateTime and well as DATE structure. I have also tried to use CString with a Format statement to Float. My problem is I do not know how to convert the above C++ structures to SQL DateTime Structure.
Never miss a deadline with

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

There is no standard SQL datetime structure (it varies depedning on DB).

However, there is a standard variant datetime type - which you need to convert to.

Use a COleVariant (or _variant_t) - this has conversion functions galore.
Do u want to convert into
ODBC Date time Struct.
rianAuthor Commented:
As long as the ODBC Date Time Struct is similar to the Microsoft
SQL Server 7.0 Date time structure.
C++ has no date structure.  What are you cxonverting from?  SQL has TIMESTAMP.  Is that the destination type?
rianAuthor Commented:
Sure does. CDateTime, Date, COleDateTime are all DateTime structures. SQL has a DATETIME structure.
rianAuthor Commented:
Thanks again.
All Courses

From novice to tech pro — start learning today.