Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Answer: How do I incorporate a timestamp into a file name?

( #93266=categorized answer: print w/ replies, xml ) Need Help??

Q&A > dates and times > How do I incorporate a timestamp into a file name? contributed by bikeNomad

The easiest way to do it (assuming you don't need to have humans interpret it) is to just use the numeric return value from time():

my $filename = $directory . '/' . time() . '.ext';
Otherwise, you can put together the various numbers from localtime:

my @lt = localtime(time); my $filename = sprintf "%s/%04d%02d%02d%02d%02d%02d", $directory, $lt[ +5]+1900, $lt[4]+1, @lt[3,2,1,0];

Comment on Answer: How do I incorporate a timestamp into a file name?
Select or Download Code
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (10)
As of 2015-07-08 03:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (94 votes), past polls