Forum Moderators: coopster & phranque

Message Too Old, No Replies

date arithmetic

calculate time elapsed since the directory has been written to

         

bigshow

11:06 pm on Jun 15, 2005 (gmt 0)

10+ Year Member



I'm new to perl....

I wish to get the date & timestamp of a unix directory; then get the current time; and finally calculate time elapsed since the directory has been written too.

I think i can get the directory date stamp with:
$dir_name="test_dir";
($WRITETIME)=(stat($dir_name))[9];

This I is believe gives me the epoch time.

I now need the current time (in epoch) so that I can subtract one from the other to work out the number of seconds since the directory has been written to.

How do I do this?

Any help would be much appreciated :0)

rocknbil

11:37 pm on Jun 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



lookup time or localtime, it functions very similarly to stat. Just no file attributes.

bigshow

8:41 am on Jun 16, 2005 (gmt 0)

10+ Year Member



I've tried looking these up but am struggling to head my head round it.

Can somebody post a working example?

Romeo

9:28 am on Jun 16, 2005 (gmt 0)

10+ Year Member



Hi Bigshow, welcome to Webmasterworld.

To get the current epoch time (seconds since 1970):
$now = time;

Example code (not tested):
@stats = stat($filename);
$filetime = $stats[9];
$now = time;
$difference = $now - $filetime;
print "File $filename last modified $difference seconds ago\n";

Regards,
R.