Hello, I'm trying to get a date from a database, and display it in a listview control.

I connect successfully to the DB, query it, then bind the cols:



invoke SQLBindCol, hStmt,1,SQL_C_CHAR, addr Session_ID, sizeof Session_ID, addr Session_ID_Length
invoke SQLBindCol, hStmt,2,SQL_C_TYPE_DATE,ADDR Session_Date,SIZEOF Session_Date,ADDR Session_Date_Length


Session_Date is a SYSTEMTIME structure.
I then populate the LVcontrol, first using:


invoke GetDateFormat,NULL,NULL,ADDR Session_Date,ADDR sDateFormatString,ADDR somebuffer,SIZEOF somebuffer

to format the date string. However, the dates are always displayed, for example, as "00 August, 2003", the days are always "00". Whereas in the DB the day would be "27" etc. Can anyone help?

The database is MSAccess 2000 format. The date field is of type "Long Date". However, if I change this to "General Date", so that a time is included, the hour, i.e 19 for 19:00, is displayed as the day. :confused:

I hope I've explained this okay, would really appreciate some ideas, I've tried using SQL_C_TYPE_TIMESTAMP in the SQLBindCol call, have tried different date formats in the DB...
Thanks a lot,
~Jan
Posted on 2003-07-09 09:47:02 by adamjjackson
Okay, I think I know the problem. I have changed some of my code, so that now when calling SQLBindCol I specify SQL_C_TYPE_TIMESTAMP as the target type, since I am retreiving a general date (date and time field), this is then stored in a TIMESTAMP_STRUCT structure, which is defined as follows:


TIMESTAMP_STRUCT struct
year dw ?
month dw ?
day dw ?
hour dw ?
minute dw ?
second dw ?
fraction dd ?
TIMESTAMP_STRUCT ends


However, the GetDateFormat and GetTimeFormat API's which I wish to use to format the date operate on a SYSTEMTIME structure, defined as follows:


SYSTEMTIME STRUCT
wYear WORD ?
wMonth WORD ?
wDayOfWeek WORD ?
wDay WORD ?
wHour WORD ?
wMinute WORD ?
wSecond WORD ?
wMilliseconds WORD ?
SYSTEMTIME ENDS


I'm not sure how to proceed from here, how do I get my dates from the TIMESTAMP_STRUCT into a nice format to show in the ListView control? Is there anyway to convert one strucure to the other?
Thanks in advance,
~Adam
Posted on 2003-07-10 10:32:54 by adamjjackson
Okay, I guess everyone know this then, but may as well complete the thread! All I've done is to push a member of the TIMESTAMP_STRUCT onto the stack, then pop it into the corresponding member of the SYSTEMTIME structure. I didn't expect this to work, since I am moving a variable that is potentially a DWORD, into a one that is a WORD. If anyone can explain why this works, I'd be interested. I guess that everything in the TIMESTAMP_STRUCT is a WORD, but then why define them as DWORDs?!

Also, it just seems a bit messy, is there a better way than what I have?


push Session_Date.year
pop dDate.wYear
push Session_Date.month
pop dDate.wMonth
push Session_Date.day
pop dDate.wDay
push Session_Date.hour
pop dDate.wHour
push Session_Date.minute
pop dDate.wMinute

...where Session_Date is the TIMESTAMP_STRUCT structure, and dDate is the SYSTEMTIME structure.
See ya!
Posted on 2003-07-11 10:45:20 by adamjjackson