Link to home
Start Free TrialLog in
Avatar of rian
rian

asked on

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.
Avatar of abancroft
abancroft

Which C++ date type are you using?

By "DateTime" I assume you mean adDBTimeStamp?
Avatar of rian

ASKER

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.
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.
Avatar of rian

ASKER

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?
Avatar of rian

ASKER

Sure does. CDateTime, Date, COleDateTime are all DateTime structures. SQL has a DATETIME structure.
ASKER CERTIFIED SOLUTION
Avatar of abancroft
abancroft

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rian

ASKER

Thanks again.