Is there any method in MFC to convert date in the format (yyyy-mm-dd) to (dd-mm-yyyy). The date is given as an input ,where the user type the date in yyyy-mm-dd format . Thanks in advance.
Asked
Active
Viewed 1,912 times
1 Answers
0
If you know the input string is in "yyyy-mm-dd" format, then you can do a simple string rewrite of the form:
out[0] = in[8];
out[1] = in[9];
out[2] = '-';
...
If the input string is not formatted that nicely, then you will actually need to parse the date string, which is a harder problem.
The standard way to do that is using strptime(), as discussed in:
Convert a string to a date in C
where the format string would look like "%Y-%m-%d".
Once you have the date, you could print it using something like:
printf("%.4d-%.2d-%.2d", tm->tm_year, tm->tm_mon, tm->tm_mday);

Community
- 1
- 1

Carl Staelin
- 1,067
- 10
- 9