String convert in Date

Hello Everybody,
I have a CString and it is like "[CPLM]......27.12.1999" and I would like to convert string (27.12.1999) in Date , because I need 27.12.1999 for some calcutaions.
I have just tryed to work with ParseDateTime(), but it did not worked.

If you could help me , I will be very happy
thank you very much
ParseDateTime() will not work since it does not support this kind of format, instead try 27 December 1999.
The list of string formats which are supported by ParseDateTime(LPCTSTR, dFlag, LCID)
1
2
3
4
5
6
7
"27 December 1999"
"8:30:00"
"20:30:00"
"January 25, 1996 8:30:00"
"8:30:00 Jan. 25, 1996"
"1/25/1996 8:30:00"  // always specify the full year,
                                  // even in a 'short date' format 

so, if you can some how convert your string to the specified format..
Hallo,
I tryed but it is still not working

Hier is my code:
1
2
3
			inf="27 December 1999";
			COleDateTime t,k; //Test
			k==t.ParseDateTime(inf);//Test 

is ist not true , what i did??

thank you for your help
If you cannot alter the string due to some reasons then suggestion is not to re-invent the wheel just peep in time.h STL


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <stdio.h>
#include <locale.h>
#include <time.h>
 
int main(void)
{
    char buf[100];
    time_t t;
    struct tm *timeptr,result;
 
    setlocale(LC_ALL,"/QSYS.LIB/EN_US.LOCALE");
    t = time(NULL);
    timeptr = localtime(&t);
    strftime(buf,sizeof(buf), "%a %m/%d/%Y %r", timeptr);
 
    if(strptime(buf, "%a %m/%d/%Y %r",&result) == NULL)
          printf("\nstrptime failed\n");
   else
   {
          printf("tm_hour:  %d\n",result.tm_hour);
          printf("tm_min:  %d\n",result.tm_min);
          printf("tm_sec:  %d\n",result.tm_sec);
          printf("tm_mon:  %d\n",result.tm_mon);
          printf("tm_mday:  %d\n",result.tm_mday);
          printf("tm_year:  %d\n",result.tm_year);
          printf("tm_yday:  %d\n",result.tm_yday);
          printf("tm_wday:  %d\n",result.tm_wday);
   }
 
   return 0;
}


don't forget to:
 
char *strptime(const char *buf, const char *format, struct tm *tm);

in header..


you need to pass the right flag (VAR_DATEVALUEONLY, ..) as well.
else it will be using your locale and that's not a valid date format for your locale.
Topic archived. No new replies allowed.