Insert file date created into a variable

Discussion in 'Perl' started by Chris Petersen, Nov 5, 2003.

  1. Is there a better/simpler way than this?

    use POSIX ('strftime');
    my $dateCreated = strftime "%b %d, %Y %H:%M", localtime
    ((stat("c:\\test.txt"))[10]);

    How would I go about displaying the output in this format: 20031105
    14:00? Any advice of links would be appreciated. Thanks in advance
    -Chris
    Chris Petersen, Nov 5, 2003
    #1
    1. Advertising

  2. -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    (Chris Petersen) wrote in
    news::

    > Is there a better/simpler way than this?
    >
    > use POSIX ('strftime');
    > my $dateCreated = strftime "%b %d, %Y %H:%M", localtime
    > ((stat("c:\\test.txt"))[10]);
    >
    > How would I go about displaying the output in this format: 20031105
    > 14:00? Any advice of links would be appreciated. Thanks in advance
    > -Chris


    This is why I wrote Time::Format. I got sick of looking up the awkward
    strftime %-codes, and was tired of having to make do when they weren't
    flexible enough.

    use Time::Format;
    my $dateCreated = time_format('yyyymmdd hh:mm',(stat $file)[10]);

    http://search.cpan.org/~roode/Time-Format-0.13/Format.pm

    Hope it helps.
    - --
    Eric
    $_ = reverse sort $ /. r , qw p ekca lre uJ reh
    ts p , map $ _. $ " , qw e p h tona e and print

    -----BEGIN PGP SIGNATURE-----
    Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

    iQA/AwUBP6mISWPeouIeTNHoEQLZQwCgnh5zmXI0rLBQYUzcMWpEU/T4dO0An28m
    Qv8YB1yVKzx0ofBrlLrcFPfw
    =0SEz
    -----END PGP SIGNATURE-----
    Eric J. Roode, Nov 5, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Peter Grison

    Date, date date date....

    Peter Grison, May 28, 2004, in forum: Java
    Replies:
    10
    Views:
    3,251
    Michael Borgwardt
    May 30, 2004
  2. pristo
    Replies:
    24
    Views:
    1,110
    Chris Torek
    Nov 10, 2005
  3. Replies:
    5
    Views:
    257
  4. Chris Petersen

    Insert file date created into a variable

    Chris Petersen, Nov 5, 2003, in forum: Perl Misc
    Replies:
    5
    Views:
    126
    Steve Grazzini
    Nov 6, 2003
  5. Sergio del Amo
    Replies:
    4
    Views:
    233
Loading...

Share This Page