Split current date

Hi,
I have to categorize the time into hour basic and day basic. I am using NOW() to store the current time. Here the time stores as "2013-06-22 13:40:04", I need to get the day of this time.(i.e. Monday, Tuesday...). And I need that hour also(i.e. from "13:40:04" I need "13" only). So first I have to separate the date and then have to find the day and hour from it.

How to do it?

1
2
3
4
5
6
7
 conn = mysql_init(NULL);
  mysql_real_connect(conn,"","root","root","trafficdetails",0,NULL,0);
  std::cout << "Total: " << totalcount << " cars" << std::endl;

  std::ostringstream query;
  query << "Insert into details (time , count) values(NOW(), '" << totalcount << "' )";
  mysql_query(conn, query.str().c_str());


Thanks in advance
Last edited on
I've got it.. This is the way..


time_t rawtime;
struct tm * timeinfo;
char buffer [80];
char buffer1 [80];
char buffer2 [80];

time (&rawtime);
timeinfo = localtime (&rawtime);

////strftime (buffer,80,"%c:%A",timeinfo);
strftime (buffer,80,"%H",timeinfo);
strftime (buffer1,80,"%A",timeinfo);

////strftime (buffer2,80,"%R",timeinfo);

////puts (buffer);
printf(buffer);

Topic archived. No new replies allowed.