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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.
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.
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

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.
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());

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rianAuthor Commented:
Thanks again.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.