Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

How do I interpret mtime with stat()?

by Anonymous Monk
on Oct 21, 2000 at 10:35 UTC ( #37789=categorized question: print w/replies, xml ) Need Help??
Contributed by Anonymous Monk on Oct 21, 2000 at 10:35 UTC
Q&A  > directories


With: $mtime = (stat $filename)[9];
I get a number. What do I do with that number?

Answer: How do I interpret mtime with stat()?
contributed by mitd

mtime as returned by (stat($filename))[9] is seconds since the epoch on your particular platform.
To see when the beginning of your machine's epoch was:

print scalar gmtime(0);

Some modules useful for working with date/time:

Answer: How do I interpret mtime with stat()?
contributed by extremely

mtime is the number of seconds since 1970 (at least on UNIX-ish systems).
You can compare it to time() to see how old the file is.

my $mtime = (stat $filename)[9]; my $age = time() - $mtime; die "HEY! $filename was created in the future!\n" if $age < 0; print "$filename is $age seconds old\n";
Answer: How do I interpret mtime with stat()?
contributed by Klem

If you don't need the other stuff that comes from stat(), you may want to consider using the -M file test operator, which yields the age (since 'last modified') for the file, in (fractional) days.

Answer: How do I interpret mtime with stat()?
contributed by Anonymous Monk

if you want to know everything about the time, use the localtime function:

my $mtime = (stat $filename)[9]; my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($m +time);
All list elements are numeric, and come straight out of a struct tm. ... In particular this means that #mon has the range 0..11, $wday has the range 0..6, and the year has had 1,900 subtracted from it. (You can remember which ones are 0-based because those are the ones you're always using as subscripts into 0-based arrays containing the month and day names.)

Please (register and) log in if you wish to add an answer

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others chilling in the Monastery: (8)
    As of 2018-07-19 21:14 GMT
    Find Nodes?
      Voting Booth?
      It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

      Results (420 votes). Check out past polls.