Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File modification date

Status
Not open for further replies.

DonP

IS-IT--Management
Jul 20, 2000
684
US
I'm trying to use stat($filename) to get the last changed date of the file. Is the resulting number what I want and can it be converted to something readable? $mtime gives 983598526.

($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size, $atime,$mtime,$ctime,$blksize,$blocks) = stat($filename);

print "$mtime";

Or is there another way to do it?

Don
don@ctagroup.org
Experienced in HTML, Perl, VBScript, PWS, IIS and Apache. Run OS/2 Warp 4, BeOS v5 and Windows NT (only when I have to!)
 
localtime() will do it...

Do perldoc -f localtime for more info...

Disclaimer:
Beware: Studies have shown that research causes cancer in lab rats.
 
Doesn't this just get the current time? I'm trying to get the time and date another file was last saved, and to present the date in a way that is understandable. I did look at (and printed out) the perldoc you suggested (thanks!) but I'm afraid it is a little beyond my abilities. With it, I was able to print out the current time and date but nothing else.

Don
don@ctagroup.org
Experienced in HTML, Perl, VBScript, PWS, IIS and Apache. Run OS/2 Warp 4, BeOS v5 and Windows NT (only when I have to!)
 
Can you try and evaluate that in an array context?

@file_attr = stat($filename);

and then look at the individual array elements Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
localtime() doesn't give the local time, it converts the huge stupid number you had into an array of data which will be readable as time.
to get the current system time:
localtime(time())
is what you use. however the format of the returned array is something like:
(sec, min, hour, day, month-1, year-1900, weird stuff...)
(look it up in the docs for exact)

if you just wanna compare two dates, you should leave it in the form you have it currently, as it is numeric and easy to compare to other numbers. converting it only helps if you need to know one specific detail about the time, or if you want to print it in human readable format. to convert, just say:
my @arr = localtime($mtime);
and pull it apart from there.

HTH "If you think you're too small to make a difference, try spending a night in a closed tent with a mosquito."
 
Thanks! It is beginning to make sense. I was getting the long string but had no idea what to do to make sense of it, but I'm beginning to understand. I really don't care about the time, only the date, and it is only the date of a file with no comparison to anything else at all that I need.

Don
don@ctagroup.org
Experienced in HTML, Perl, VBScript, PWS, IIS and Apache. Run OS/2 Warp 4, BeOS v5 and Windows NT (only when I have to!)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top