1

I have inherited some MFC C++ code (it's an ActiveX OCX control running on a Windows Mobile 6.5 device) and I need to acquire the system date and time and append it as part of an existing string which gets passed via the com port to another device.

I can get the system date and time, but I can not figure out how to convert that into a string so that I can append it (via strcat.)

I've found a number of different answers on Google and Bing for what at first glance seemed like such a simple problem... :( but I don't know enough MFC C++ to adapt any of it to my needs. Any help would be greatly appreciated.

C Williams
  • 11
  • 1
  • 2

2 Answers2

3
CTime t = CTime::GetCurrentTime();
CString s = t.Format( "%A, %B %d, %Y" );
char * str = (LPCTSTR) s;

Note, I believe that str is only valid while s is in scope. Probably should copy it off somewhere if you need it to be around after s is destroyed. If you are passing it to strcat() you're probably OK.

Dave Rager
  • 8,002
  • 3
  • 33
  • 52
1

In MFC the following code is for current date in MMDDYYYY format.

CTime t = CTime::GetCurrentTime();
CString strDate = t.Format("%m%d%Y");
Pabitra Dash
  • 1,461
  • 2
  • 21
  • 28