Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Please help with GetFileTime 1

Status
Not open for further replies.

phlat

Programmer
Dec 8, 2004
6
US


I'm not really a C programmer but I know enough to be dangerous. How can I assign the file created date via GetFileTime to szOptionalField1? Thanks!

struct _FILETIME ft;SYSTEMTIME stUTC, stLocal;

GetFileTime(szCsvFile,&ft,NULL,NULL);
FileTimeToSystemTime(&ft, &stUTC);
SystemTimeToTzSpecificLocalTime(NULL, &stUTC, &stLocal);

//stLocal.wMonth, stLocal.wDay, stLocal.wYear

char *szOptionalField1 = "PrintDateHere";
 
First, you need to declare your string with enough space to fit the largest possible date. You need to decide what format you'd like the date to be displayed in...

I'll take a guess and say you'd like it in this format:
mm/dd/yyyy hh:mm:ss

Here's one way to do it (in C):
Code:
char szOptionalField1[20];

sprintf( szOptionalField1, %2d/%2d/%4d %2d:%2d:%2d", stLocal.wMonth, stLocal.wDay, stLocal.wYear, stLocal.wHour, stLocal.wMinute, stLocal.wSecond );
printf( "The time is: %s\n", szOptionalField1 );

Since this is a C++ forum you're posting in, here's how to do it in C++:
Code:
stringstream optionalField1;

optionalField1 << stLocal.wMonth << "/" << stLocal.wDay << "/" << stLocal.wYear << " " << stLocal.wHour << ":" << stLocal.wMinute << ":" << stLocal.wSecond;
cout << "The time is: " << optionalField1.str() << endl;
 
Thank you! This is what I've been trying to do. I am using VC++ BTW
 
Or you can just us the GetDateFormat() API

Greetings,
Rick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top