Get a DateTime from a Table

Hello ,
I'd like to get a a field name "eventDateTime" from a DB table and its storage is datetime year to fraction (3) .

I have created a function return results like this but i put its type as a int:

int Status::GetEventFromSQL(){
int j = 0;
int eventTime = 0;
MYSQL_ROW myROW;
MYSQL_RES *myRES = NULL;
if(!mysql_query(Connexion, "SELECT eventDateTime FROM agentstatdetail WHERE(eventDateTime > today - 1) "))
{
myRES = mysql_store_result(Connexion);
if(myRES)
{
for(j = 0; j < myRES->row_count; j++)
{
myROW = mysql_fetch_row(myRES);
sscanf(myROW[0],"%i",&eventTime);
Agent[j]->eventTime = eventTime;
}
}
mysql_free_result(myRES);
myROW = NULL;
myRES = NULL;
}
return 0;
}
" eventTime " is also declared in another sheet .h as an int.

In execution i have a big and negative number ; I know that's because of the int type but i'm bigenner in C++...

Thanks for help

karima
You have to be clear about what you want. The DB stores your field as a dattime. But what format do you want to receive it in?

I mean, do you want it as a string, ... You've specified an int; but what does that mean (to you)?

Further reading:
https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html
1. Could you please edit your code in your post using tags:
http://www.cplusplus.com/articles/jEywvCM9/

2. What is the format of the string you're parsing (or trying to parse...) with scanf?

The MySQL server I'm running is pre-5.6.4 so can't do the fractional seconds in dates, but the strings I get for a DATETIME column are like;

2013-10-13 19:32:52
2013-11-04 18:15:11
2013-12-25 01:45:13
...


and I would expect your strings to be that plus the fractional seconds, e.g.

2013-10-13 19:32:52.123


which isn't going to be parsed using scanf with "%i"

Andy
Last edited on
Topic archived. No new replies allowed.