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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Saving file down in date format

Status
Not open for further replies.

Helfenmir

MIS
Sep 17, 2001
61
GB
Hi
I need to change a file name and save it down in a different folder with the current date as determined by the system clock ie. <date>.txt the date format needs to be YYMMDD. Can anyone help me please.

Many Thanks
Helfenmir
 
Hi,

try with:

#include <time.h>

struct tm *pnow ;
long tnow ; /* or time_t, see your doc */
FILE *stream ;
char fullname[80];
......

time( &tnow ) ;
pnow = localtime( &tnow ) ; // see difference with gmtime
// the area tm is internal at
// the system function

sprintf( fullname, &quot;%s%02d%02d%02d.txt&quot;,
&quot;mypath&quot;, // warning at / or \\ if unix or dos
pnow->tm_year - 1900, // warining at millenium bug ??
pnow->tm_mon + 1, // Jan = 0 ??
pnow->tm_day ) ;

stream = fopen( fullname, &quot;w&quot; ) ; // test
fclose( stream );

-------

However, see doc in your implementation, for types and
include files, and resolve the millenium bug.


Bye
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top