mrnobody 0 Junior Poster in Training

Hi,
I'm doing a code in MFC to retrieve DateTime from SQL 2005 and then after do datetime manipulation on it.

In the SQL table, the date field is 3/16/2010 2:28:20 PM (obtained by using getdate()).

I then retrieve the date from RecordSet and stored into _variant_t.
To confirm that the data received is correct, I convert it to CString by using the code below. The value converted is the same as the one in database.

_variant_t var = pRs->GetCollect(_variant_t("Date"));
var.ChangeType(VT_BSTR);
CString str = var.bstrVal;

Then, I use the code below to try to convert the value into time_t so that I can manipulate the time.

var.ChangeType(VT_DATE);
str = var.lVal;      //I use lVal because time_t is type long int right..?
CString str = ctime (&var.lVal);    //Convert the long value of time into string to confirm the value before continue.

Here is where I'm stuck. str give me "Fri Apr 30 07:15:03 2010" which is wrong. What I was hoping to get is "Tue Mar 16 14:28:20 2010". Can somebody please advice me on where I go wrong and how to rectify it.. Thanks..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.