tags:

views:

69

answers:

3

how to find the file is created or updated current date/day

+3  A: 

You could use the -M function to see if the file has been modified in the last day:

if(-M FH < 1) {
    # file was modified less than one day ago
}

You can also test for time since the inode was changed with -C, which is often (but not always) when the file was created (see here for filesystem compatibility issues).

See here for some examples of the various filetests.

Jeremy Smyth
+1  A: 

Show on File::Stat. You can use DateTime to init the timestamp with local time zone.

xGhost
+2  A: 

Assuming that you want day and date of the file when it was last modified, you can try like this

use strict;
use warning;
use File::stat;
use Time::localtime;

my $st = stat($file) or die "No $file: $!";
my $datetime_string = ctime($st->mtime);

print "file $file was updated at $datetime_string\n";
Nikhil Jain