Click here to Skip to main content
16,005,473 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: C Library Pin
Hamid_RT27-Aug-08 4:29
Hamid_RT27-Aug-08 4:29 
QuestionCode Send in DLL Pin
nedracix26-Aug-08 22:57
nedracix26-Aug-08 22:57 
QuestionRe: Code Send in DLL Pin
CPallini26-Aug-08 23:04
mveCPallini26-Aug-08 23:04 
QuestionRe: Code Send in DLL Pin
David Crow27-Aug-08 3:16
David Crow27-Aug-08 3:16 
AnswerRe: Code Send in DLL Pin
Hamid_RT27-Aug-08 4:28
Hamid_RT27-Aug-08 4:28 
QuestionHow to append current Date and time to the name of a text file programmatically? Pin
kapardhi26-Aug-08 22:47
kapardhi26-Aug-08 22:47 
AnswerRe: How to append current Date and time to the name of a text file programmatically? Pin
_AnsHUMAN_ 26-Aug-08 22:57
_AnsHUMAN_ 26-Aug-08 22:57 
AnswerRe: How to append current Date and time to the name of a text file programmatically? Pin
Nibu babu thomas26-Aug-08 23:00
Nibu babu thomas26-Aug-08 23:00 
kapardhi wrote:
I am creating an XYZ.txt file in my project,
i want that each time the XYZ.txt is created the name must be not simple as XYZ.txt, but it must be XYZ_DATE_TIME.txt

XYZ_27-08-2008_02-12.txt
XYZ_27-08-2008_16-45.txt


You can use functions _strdate_s and _strtime_s for getting time and date as string...

Quickly typed in a function which does this...

CString CreateFileNameWithTimeStamp( LPCTSTR lpctszTitle, LPCTSTR lpctszExtension )
{
   CString csFileNameWithTimeStamp = lpctszTitle;

   // Temporary buffer for date and time
   const int BuffSize = 50;
   TCHAR szBuff[BuffSize] = { 0 };

   // First append date
   _strdate_s( szBuff, BuffSize );
   csFileNameWithTimeStamp += "_";
   csFileNameWithTimeStamp += szBuff;

   // Then time
   _strtime_s( szBuff, BuffSize );
   csFileNameWithTimeStamp += "_";
   csFileNameWithTimeStamp += szBuff;

   // Then extension
   csFileNameWithTimeStamp += lpctszExtension;

   // Remove forward slash and colons from file name
   csFileNameWithTimeStamp.Replace( _T( '/' ), _T( '_' ));
   csFileNameWithTimeStamp.Replace( _T( ':' ), _T( '_' ));

   // Now return new file name
   return csFileNameWithTimeStamp;
}


How to call?
CString csFileName = CreateFileNameWithTimeStamp( _T( "ABC" ), _T( ".txt " ));


Output looks like...

ABC_08_27_08_14_27_34.txt


Nibu babu thomas
Microsoft MVP for VC++


Code must be written to be read, not by the compiler, but by another human being.

Programming Blog: http://nibuthomas.wordpress.com

AnswerRe: How to append current Date and time to the name of a text file programmatically? Pin
Jijo.Raj26-Aug-08 23:10
Jijo.Raj26-Aug-08 23:10 
QuestionMem leak Pin
tom groezer26-Aug-08 22:43
tom groezer26-Aug-08 22:43 
AnswerRe: Mem leak Pin
Nibu babu thomas26-Aug-08 22:49
Nibu babu thomas26-Aug-08 22:49 
GeneralRe: Mem leak Pin
CPallini26-Aug-08 23:03
mveCPallini26-Aug-08 23:03 
GeneralRe: Mem leak Pin
Nibu babu thomas26-Aug-08 23:42
Nibu babu thomas26-Aug-08 23:42 
AnswerRe: Mem leak Pin
Jijo.Raj26-Aug-08 22:55
Jijo.Raj26-Aug-08 22:55 
GeneralRe: Mem leak Pin
tom groezer27-Aug-08 0:17
tom groezer27-Aug-08 0:17 
GeneralRe: Mem leak Pin
toxcct27-Aug-08 0:45
toxcct27-Aug-08 0:45 
GeneralRe: Mem leak Pin
tom groezer27-Aug-08 1:40
tom groezer27-Aug-08 1:40 
Questionclosing or destroying a dialog box Pin
Dhiraj kumar Saini26-Aug-08 22:42
Dhiraj kumar Saini26-Aug-08 22:42 
AnswerRe: closing or destroying a dialog box Pin
CPallini26-Aug-08 22:51
mveCPallini26-Aug-08 22:51 
QuestionLinking Error Pin
NewVC++26-Aug-08 22:20
NewVC++26-Aug-08 22:20 
AnswerRe: Linking Error Pin
Jijo.Raj26-Aug-08 22:37
Jijo.Raj26-Aug-08 22:37 
AnswerRe: Linking Error Pin
CPallini26-Aug-08 22:39
mveCPallini26-Aug-08 22:39 
AnswerRe: Linking Error Pin
Roger Stoltz26-Aug-08 22:39
Roger Stoltz26-Aug-08 22:39 
AnswerRe: Linking Error Pin
cp987626-Aug-08 23:13
cp987626-Aug-08 23:13 
QuestionHow to view the contents of stl::map in debug Pin
kbshibukumar26-Aug-08 21:26
kbshibukumar26-Aug-08 21:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.