473,385 Members | 1,934 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Filnames and timestamps

Hello out there,

I would like to create a filename where the name of the file is:

ERRORS_MMDDYYYY_HHMMSS.

Is there a way that this can be done?

Any help, hints or advice would be appreciated ;-)

TIA

Nov 15 '05 #1
8 2978

milkyway wrote:
Hello out there,

I would like to create a filename where the name of the file is:

ERRORS_MMDDYYYY_HHMMSS.

Is there a way that this can be done?

Any help, hints or advice would be appreciated ;-)

TIA


Look up localtime and sprintf.

-David

Nov 15 '05 #2
>I would like to create a filename where the name of the file is:

ERRORS_MMDDYYYY_HHMMSS.

Is there a way that this can be done?


sprintf() is your friend when constructing filenames (or other
strings) from pieces, although in this case strftime() may be more
useful. And, of course, there's fopen() to actually create the
file.

If the time desired is the CURRENT time, use time() to get the time
(a time_t) and localtime() to break it down into something suitable
(a struct tm) to feed to strftime().

Gordon L. Burditt
Nov 15 '05 #3
Thanks but are there any sample programs of how to use this lying
around?

Nov 15 '05 #4
Please preserve some context when posting replies.

"milkyway" <d0******@hotmail.com> wrote:

[ I would like to create a filename where the name of the file is:
ERRORS_MMDDYYYY_HHMMSS. ]
Thanks but are there any sample programs of how to use this lying
around?


A quick and dirty demo program:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#define FILENAMELEN 23

int main( void )
{
char filename[FILENAMELEN];
time_t curtime;
struct tm *loctimep;

curtime = time( NULL );
if ( curtime == -1 )
{
fputs( "Calendar time not available\n", stderr );
exit( EXIT_FAILURE );
}

loctimep = localtime( &curtime );
if ( loctimep == NULL )
{
fputs( "Time conversion error\n", stderr );
exit( EXIT_FAILURE );
}

if ( strftime( filename, FILENAMELEN,
"ERRORS_%m%d%Y_%H%M%S", loctimep ) == 0 )
{
fputs( "Generated filename too long\n", stderr );
exit( EXIT_FAILURE );
}

printf( "Generated filename: %s\n", filename );
exit( EXIT_SUCCESS );
}
HTH
BEst regards
--
Irrwahn Grausewitz (ir*******@freenet.de)
welcome to clc : http://www.ungerhu.com/jxh/clc.welcome.txt
clc faq-list : http://www.faqs.org/faqs/C-faq/faq/
clc frequent answers: http://benpfaff.org/writings/clc
Nov 15 '05 #5
Thank you ;-)

Nov 15 '05 #6
milkyway wrote on 13/09/05 :
I would like to create a filename where the name of the file is:

ERRORS_MMDDYYYY_HHMMSS.

Is there a way that this can be done?

Any help, hints or advice would be appreciated ;-)


A file name is just another string.

time()
localtime()
strftime()

--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
The C-library: http://www.dinkumware.com/refxc.html

"Clearly your code does not meet the original spec."
"You are sentenced to 30 lashes with a wet noodle."
-- Jerry Coffin in a.l.c.c++
Nov 15 '05 #7
Irrwahn Grausewitz wrote on 14/09/05 :
if ( strftime( filename, FILENAMELEN,
"ERRORS_%m%d%Y_%H%M%S", loctimep ) == 0 )


Correct, but there is a design issue : for future chronological sort
help, I recommend to use the ISO date format

if (strftime (filename, FILENAMELEN,
"ERRORS_%Y%d%m_%H%M%S", loctimep) == 0)

--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
The C-library: http://www.dinkumware.com/refxc.html

"There are 10 types of people in the world today;
those that understand binary, and those that dont."
Nov 15 '05 #8
"Emmanuel Delahaye" <em***@YOURBRAnoos.fr> wrote:
Irrwahn Grausewitz wrote on 14/09/05 :
if ( strftime( filename, FILENAMELEN,
"ERRORS_%m%d%Y_%H%M%S", loctimep ) == 0 )


Correct, but there is a design issue : for future chronological sort
help, I recommend to use the ISO date format

if (strftime (filename, FILENAMELEN,
"ERRORS_%Y%d%m_%H%M%S", loctimep) == 0)


Right, I'd do the same, I just wanted to stick with the OP's
filename format specification:
> ERRORS_MMDDYYYY_HHMMSS


Additionally, my code miserably fails if year > 9999. :)

Best Regards
--
Irrwahn Grausewitz (ir*******@freenet.de)
welcome to clc : http://www.ungerhu.com/jxh/clc.welcome.txt
clc faq-list : http://www.faqs.org/faqs/C-faq/faq/
clc frequent answers: http://benpfaff.org/writings/clc
Nov 15 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: lkrubner | last post by:
This might be an idiot question, but how do you group by timestamps by date? I mean, given a large number of timestamps, spanning many months, how do grab them and say how many are from each day?...
10
by: Craig Wahlmeier | last post by:
Am I the only one in the world that selects dates and timestamps with OLEDB? V8 of UDB has brought me a big problem. The PATCH2=24 setting no longer works the way it used to. The settings of...
5
by: Robert Schuldenfrei | last post by:
Dear NG, I have not heard from anyone about a good book that deals with the concurrency issue in SQL Server using C#. I have PROMISED Nick I would not use record locking and I have used an old...
2
by: Chumma Dede | last post by:
Hi, I need to code a DLL in .NET which logs the response times for our asp.net multi-tier application. The problem is we need to log the timestamps at multiple stages in a process lifecycle...
4
by: Craig G | last post by:
im not too sure how i should be storing the SQL2000 timestamps basically i return a dataset which is used to populate an editable grid. this dataset contains the timestamp. how should i be...
1
by: Erwin Van de Velde | last post by:
Hi, I'm building a central logging system for security applications as my master thesis, but I've run into some troubles: Different applications make database logs using different formats: -...
3
by: rAinDeEr | last post by:
Hi, Is there any performance issues related to having default timestamps in tables? I have a Data Model in which all the tables have created_tms and last_updated_tms which I have set default...
0
by: mikek | last post by:
Good Morning from Detroit, I am working on a project to Connect and manipulatee data in a SQLServer Data base, from a LINUX server using PERL. and SOAP We decided to use SOAP:Lite. (there are...
16
by: maruk2 | last post by:
I have some old data files with old timestamps, where timestmap=time(NULL), some of them date back to the year 1999. I want to my code to print the timestamps and each one to include...
6
by: xkenneth | last post by:
All, Just a quick question. I want to be able to have a data structure that organizes data (timestamps I'm working with) sequentially, so that i can easily retrieve the first x amount of...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.