Gossamer Forum
Home : Products : DBMan : Customization :

To show date that database file was last modified

Quote Reply
To show date that database file was last modified
Is there a way to get the date that the default.db file was last modified and then print that to the main log on page preferably using date format 'd/mmmm/yyyy' but not necessary

Thanks
Quote Reply
Re: To show date that database file was last modified In reply to
You can use

Code:
my ($dev,$ino,$mode,$nlink,$fuid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = stat $db_file_name;
$last_modified = &get_date($mtime);

You can modify &get_date to do your formatting, but you'll have to also modify &date_to_unix to match it.

Also, you will need to adjust your &get_date subroutine to accept input, if it hasn't been already. The first few lines of sub get_date should be:

Code:
$time = @_[0];
($time) | | ($time = time());

my ($sec, $min, $hour, $day, $mon, $year, $dweek, $dyear, $daylight) = localtime($time);

Be sure to take out the space between the two | characters. Alternatively, you could change them to "or" --

Code:
($time) or ($time = time());



------------------
JPD





Quote Reply
Re: To show date that database file was last modified In reply to
Thanks JPD ... that worked, gives me the date the file was last modified but what about the time?
My fault I should have been more specific .. sorry
Quote Reply
Re: To show date that database file was last modified In reply to
To get the time, use

Code:
$last_modified = &get_date($mtime) . " " . &get_time($mtime);

You'll need to adjust sub get_time, too. Instead of

my ($sec, $min, $hour, $day, $mon, $year, $dweek, $dyear, $daylight) = localtime(time());

use the same code that I gave you above for the change to sub get_date.



------------------
JPD





Quote Reply
Re: To show date that database file was last modified In reply to
OK good stuff ...!

Its showing me the date & time but you what .... its showing me the current date & time rather than the db files modified date & time.

It was probably doing this in the first place because I could not tell untill it displayed the time which happens to be current time.

Any suggestions as to what I've done wrong?
Quote Reply
Re: To show date that database file was last modified In reply to
Did you make the changes to sub get_date and sub get_time?


------------------
JPD





Quote Reply
Re: To show date that database file was last modified In reply to
Well I've double checked ....
perhaps you can tell me


sub get_time {
# --------------------------------------------------------
# Returns the time in the format "hh-mm-ss".
#
$time = @_[0];
($time) | | ($time = time());
my ($sec, $min, $hour, $day, $mon, $year, $dweek, $dyear, $daylight) = localtime($time);


($sec < 10) and ($sec = "0$sec");
($min < 10) and ($min = "0$min");
($hour < 10) and ($hour = "0$hour");

return "$hour:$min:$sec";
}

sub get_date {
# --------------------------------------------------------
# Returns the date in the format "dd-mmm-yy".
# Warning: If you change the default format, you must also modify the &date_to_unix
# subroutine below which converts your date format into a unix time in seconds for sorting
# purposes.
$time = @_[0];
($time) &#0124; &#0124; ($time = time());
my ($sec, $min, $hour, $day, $mon, $year, $dweek, $dyear, $daylight) = localtime($time);
my (@months) = qw!Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec!;
($day < 10) and ($day = "0$day");
$year = $year + 1900;

return "$day-$months[$mon]-$year";
}
Quote Reply
Re: To show date that database file was last modified In reply to
Let's try a different approach, then.

Instead of what I gave you before, try:

Code:
$last_modified = time() - (-M "c:/clients/Nir/default.cfg") * 86400;
$date_and_time = &get_date($last_modified) . " " . &get_time($last_modified);
print $date_and_time;

It works on my home computer, giving the same time as Windows says the file was last modified.

(Sorry about doubting you, but I've come across people who didn't follow directions and went through a long wild goose chase trying to find out what was wrong. Smile )



------------------
JPD





Quote Reply
Re: To show date that database file was last modified In reply to
It works! Thanks JPD for helping out ... much appreciated, sorry it dragged on.
Quote Reply
Re: To show date that database file was last modified In reply to
No problem. Smile

When I first read your question, I was looking for the -M flag in my Perl books. (Well, I was looking for the flags. I couldn't remember which one I wanted.) I ran into the stat function first and figured it would work just a well. Wrong!

I must have entered it in wrong or something, because it should work. But I guess all's well, since the other one works. Smile


------------------
JPD





Quote Reply
Re: To show date that database file was last modified In reply to
What perl book do you recommend?(not a reference book)
I've heard the "PerlCGI Cookbook" is rather good
Quote Reply
Re: To show date that database file was last modified In reply to
The one I was using today was "Programming Perl." Top-notch reference work. If you're just starting out, though, "Learning Perl" is very good -- easy to read, with some humor sprinkled here and there so it doesn't get too grim. Smile

"The Perl Cookbook" is quite good, but you have to know what you're looking for.

------------------
JPD