Current time minus file's datestamp time 
Author Message
 Current time minus file's datestamp time

Howdy folks!
I have posted a few questions here and everyone is very helpful. My
quandry
right now is checking a file's date and then update it if it's older
than an hour.
We keep a text file that is updated once a day manually but we would
like to make
this automatic by a time check routine.

That is

1. Check current time
2. Subtract file's last modified time
3. Older than an hour?
        Yes - Start Update Routine

I checked the FAQ and got the really nifty routine below.....

#!/usr/local/bin/perl
use File::stat;
use Time::localtime;
$file="general.txt";
$date_string = ctime(stat($file)->mtime);
print "$date_string\n";

This does a great job with getting a file's timestamp but I need to
figure the time between this and the current time and start an update
perhaps in seconds or minutes if it's aged a certain amount.

Many thanks in advance for your assistance.

Julian Cook



Wed, 04 Dec 2002 03:00:00 GMT  
 Current time minus file's datestamp time
...

Quote:
> right now is checking a file's date and then update it if it's older
> than an hour.
> We keep a text file that is updated once a day manually but we would
> like to make
> this automatic by a time check routine.

> That is

> 1. Check current time
> 2. Subtract file's last modified time
> 3. Older than an hour?
>         Yes - Start Update Routine

> I checked the FAQ and got the really nifty routine below.....

> #!/usr/local/bin/perl
> use File::stat;
> use Time::localtime;
> $file="general.txt";
> $date_string = ctime(stat($file)->mtime);
> print "$date_string\n";

> This does a great job with getting a file's timestamp but I need to
> figure the time between this and the current time and start an update
> perhaps in seconds or minutes if it's aged a certain amount.
...
> Julian Cook


Well, just using the -M function is even easier:

   &start_update_routine if -M "filename.ext">0.04167;

Note, though, that this gives the time in fractional days between the
file's age and the time your script was started.  So if you run your
script once and loop forever with a sleep, this method won't be good.
But you shouldn't do it that way -- use your OS's scheduling utilities
to run your script periodically.
--
Bob Walton



Thu, 05 Dec 2002 03:00:00 GMT  
 Current time minus file's datestamp time
On Sat, 17 Jun 2000 21:56:42 -0400, Julian Cook/Sherab Gyatso

Quote:

>I have posted a few questions here and everyone is very helpful.

Gosh!  Can we quote you on that?  We occasionally have PR
problems... :-)

dha

--

... nononono. And to use nonononono just to negate that is, uhm,
confusing. Someone might think I'm stuttering.
        - Abigail, p5p



Thu, 05 Dec 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Current time minus file's datestamp time

2. ANNOUNCE: Time::Period - Evaluate a Time Point Relative to a Time Period

3. Displaying current date and time in specific format

4. Current Date & Time

5. Getting current time in milliseconds

6. Get current date / time?

7. How can i get current time of my PC

8. print current time

9. Calculating the current time in London or GMT+x

10. Current time milliseconds

11. Finding current time.

12. Perl module that returns current time in milliseconds

 

 
Powered by phpBB® Forum Software