0

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.

subbu
  • 3,229
  • 13
  • 49
  • 70

1 Answers1

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