Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

(jeffa) Re: File manipulation

by jeffa (Bishop)
on Mar 09, 2001 at 21:55 UTC ( [id://63287]=note: print w/replies, xml ) Need Help??


in reply to File manipulation

I prefer to store all of my timestamps as epoch seconds. Perl's built-in time returns the number of epoch seconds since January 1, 1970. As long as you have the epoch seconds, you can always figure the rest out. It's a good consistent trick to have.

For example: pick a date, what was date before that? If you picked Jan 15 then the answer is Jan 14, no matter what year. But what if you picked March 1?

However, by taking advantage of epoch seconds, you can easily figure out what yesterday was:

my $yesterday = time - (60 * 60 * 24); my ($d, $m, $y) = (localtime($yesterday))[3,4,5]; $yesterday = sprintf("%04d/%02d/%02d", $y += 1900, $m += 1, $d);

Jeff

R-R-R--R-R-R--R-R-R--R-R-R--R-R-R--
L-L--L-L--L-L--L-L--L-L--L-L--L-L--

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://63287]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2024-04-23 07:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found