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_pRs->Fields->GetItem("BUNIT")->PutValue(_bstr_t(m_BUNIT));
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.
rianAsked:
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?

e.g.

COleDateTime theDate;
COleVariant olevDate;

// Setup theDate

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

By "DateTime" I assume you mean adDBTimeStamp?
0
 
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.
0
Never miss a deadline with monday.com

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

 
abancroftCommented:
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.
0
 
basantCommented:
Do u want to convert into
ODBC Date time Struct.
0
 
rianAuthor Commented:
As long as the ODBC Date Time Struct is similar to the Microsoft
SQL Server 7.0 Date time structure.
0
 
danny_pavCommented:
C++ has no date structure.  What are you cxonverting from?  SQL has TIMESTAMP.  Is that the destination type?
0
 
rianAuthor Commented:
Sure does. CDateTime, Date, COleDateTime are all DateTime structures. SQL has a DATETIME structure.
0
 
rianAuthor Commented:
Thanks again.
0
All Courses

From novice to tech pro — start learning today.