Adding current date to the end of a string

Write your question here.
I need to add the current date to the end of a string but I only need to add the day and not the year or month.
 
  Put the code you need help with here. This is what i have

char date[9];
_strdate(date);
cout << date << endl;
You can use functions from time.h or ctime

1
2
3
time_t ti = time(0);                               //gets the current time
struct tm *current = localtime(&ti);       //converts current time of type time_t into a struct tm
cout << "Current month day value: " << current->tm_mday << endl;


Here is the definition of the struct tm
1
2
3
4
5
6
7
8
9
10
11
struct tm {
   int tm_sec;         /* seconds,  range 0 to 59          */
   int tm_min;         /* minutes, range 0 to 59           */
   int tm_hour;        /* hours, range 0 to 23             */
   int tm_mday;        /* day of the month, range 1 to 31  */
   int tm_mon;         /* month, range 0 to 11             */
   int tm_year;        /* The number of years since 1900   */
   int tm_wday;        /* day of the week, range 0 to 6    */
   int tm_yday;        /* day in the year, range 0 to 365  */
   int tm_isdst;       /* daylight saving time             */
};


Please refer to this link for the description of the function calls made above:
http://www.tutorialspoint.com/c_standard_library/time_h.htm
http://www.cplusplus.com/reference/ctime/
Last edited on
Topic archived. No new replies allowed.