I am using C++ to develop an appointment system.
Can I please have some help in converting a string to a TDateTime variable.
Here is an example that I would like some help with;
TDateTime appDateTime(2012, 9, 15, 14, 0, 0, 0);
I am saving this to a file (with other string and boolean values). When loaded in as a string, the string value is:
15/09/2012 2:00:00 pm
How can I convert this into a TDateTime variable?
thanks
UPDATE
I am trying to create the TDateTime variable via a constructor that uses a string. Here is my code:
string stringTestConstructorDate = "12/05/1990";
TDateTime testConstruct(stringTestConstructorDate);
I am getting this error: E2285 Could not find a match for 'TDateTime::TDateTime(string)'
How can I use a string variable to construct the TDateTime variable?
Here is my code for a second option:
string stringDateToConvert = "17/09/2012 09:00:02 a.m.";
struct tm DateTime;
if (NULL == strptime("17/09/2012 09:00:02 a.m.", "%D %T", &DateTime)) {
printf("strptime() failed.\n");
exit(EXIT_FAILURE);
}
printf("tm_sec = %3d\n", DateTime.tm_sec );
printf("tm_min = %3d\n", DateTime.tm_min );
printf("tm_hour = %3d\n", DateTime.tm_hour);
printf("tm_mday = %3d\n", DateTime.tm_mday);
printf("tm_mon = %3d\n", DateTime.tm_mon );
printf("tm_year = %3d\n", DateTime.tm_year);
This works well. However, can I please have some help in enabling the 'stringDateToConvert' to be passed to the 'strptime' function. Currently I am getting the following error:
E2034 Cannot convert 'string' to 'const char *'
Thanks