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!

Creating a dated log file 1

Status
Not open for further replies.

fergmj

Programmer
Feb 21, 2001
276
US
I want to create a log file to stroe information from a website. I need the log file to have the current date in yymmdd format -- such as today's log would be 010820.log

When it becomes tomorrow, it needs to create a new file called 010821.log and begin sending info to that file.

Any ideas on how I can do that?

Thanks

fergmj
 
That depends on which language you are using. Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Code:
my (undef,undef,undef,$dd,$mm,$yy,undef,undef,undef) = localtime(time);
$dd = '0'.$dd if $dd < 10;
$mm += 1;
$mm = '0'.$mm if $mm < 10;
$yy += 1900;
$yy %= 100; # if you only want last two digits of year
my $logfile = $mm.$dd.$yy;
open(LOGFILE, &quot;>>$logfile);
print &quot;whatever\n&quot;;
close LOGFILE;
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Tracy -

THANKS!

Why won't the part below work?

$currentdate = &quot;$twodigityear$realmonth$mday&quot;;
print &quot; $currentdate\n&quot;;
$beginningdate = &quot;010819&quot;;
print &quot; $beginningdate\n&quot;;

if ($currentdate =~ m/^$beginningdate/)
{
print &quot;I am equal&quot;;
$counter = $counter + 1;
}
else
{
print &quot;I am not equal&quot;;
$counter = &quot;001&quot;;
$beginningdate = $currentdate;
}

I want to set $beginningdate to something other than today and then have it reset itself to tday and remember that until it is tomorrow and so forth but it always resets to today? How dan I change that?

 
I'm not quite sure what you're trying to accomplish, but if you need to remember something like that until &quot;tomorrow&quot; you'll have to write it out to a file. Otherwise every time the program runs it starts with no memory of where it was or what it was doing the last time.

Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top