hello guys.... I have time in char[] format but I need to convert it to CString. Here is what I have but it does not work

GetSystemTime(&t);
	char time[60] = "";
	char y[20],mon[20],d[20],h[20],min[20],s[20];

	sprintf(y, "%d", t.wYear);
	sprintf(d, "%d", t.wDay);
	sprintf(mon, "%d", t.wMonth);
	sprintf(h, "%d", t.wHour+5);
	sprintf(min, "%d", t.wMinute);
	sprintf(s, "%d", t.wSecond);
	
	strcat(time,d);
	strcat(time,"/");
	strcat(time, mon);
	strcat(time,"/");
	strcat(time, y);
	strcat(time," ");
	strcat(time,h);
	strcat(time,":");
	strcat(time, min);
	strcat(time,":");
	strcat(time, s);

	CString m_strFileName = time;

Now how can I do this??...thnx

I had seen these sites. They did not work for me

CString m_strFileName(time);

What exactly didn't work and what error did it spawn?

CString has a Format() method that works exactly like sprintf(). Simplify your code like this:

CString m_strFileName.Format("%02d/%02d/%4d %02d:%02d:%02d",
  t.wDay,t.wMon,t.wYear, t.wHour,t.wMinute,t.wSecond);

Adding 5 to t.wHour can easily make t.wHour exceed 60.

@evstevemd....I am actually trying to save a txt file with Current DateTime as its name AND, since name of the file is of LPSTR type I need to convert char[] to CString untill char[] can directly be converted to LPSTR. It builds and compiles successfuly but a debug assertion is shown inwhich, unfortunately, im very poor.
Debug assertion says
Expression(stream!= NULL)

@ancient dragon....same is the case with your solution.

>> since name of the file is of LPSTR type I need to convert char[] to CString

No you don't. LPSTR is defined in windows.h as char*, so there is no need to convert char* to CString just for that purpose.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.