Reputation: 10362
how to find the file is created or updated current date/day
Upvotes: 0
Views: 2973
Reputation: 8352
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";
Upvotes: 2
Reputation: 23513
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.
Upvotes: 3
Reputation: 126
Show on File::Stat. You can use DateTime to init the timestamp with local time zone.
Upvotes: 1