Gossamer Forum
Home : Products : DBMan : Customization :

Last modified: xx.xx.xxxx.

Quote Reply
Last modified: xx.xx.xxxx.
Hi

How can I display on my homepage when the database was last modified (either record added, deleted, modified).

On the homepage should be nothing else of dbman, but only the last modified message and other html to welcome users.

It's important, so users know if database has changed.

Thanks for your help

blech

Quote Reply
Re: Last modified: xx.xx.xxxx. In reply to
$last_mod = &get_date((stat($db_file_name))[9]);

Then use the $last_mod variable to print out the last modified date.

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Last modified: xx.xx.xxxx. In reply to
Hmmm

Ok this gives me a date.

But I received the date of today 17-Aug-2000 and didn't touch the db the last 2 days ?!

Also, is there already a subroutine to transform this date format into something like 17.08.2000 ?

Thanks JPD



Quote Reply
Re: Last modified: xx.xx.xxxx. In reply to
My information is that the stat($filename)[9] function gives the date a file was last modified. Just a sec. I'll test it out.... Yep. It worked fine on my computer.

Could you post your sub get_date here? There are various versions floating around and I need to see what you have.

Do you have a date field in your database? If so, do you want all of the dates to be in the format you've listed? It makes quite a difference in the amount of coding that needs to be done in order to change the format.

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Last modified: xx.xx.xxxx. In reply to
Hi JPD

I fixed the date format myself (quite easy) but I still have the problem that the date returned is not the date of the last modification but todays date! (no joke)

Any hint?

Cheers

Blech

Quote Reply
Re: Last modified: xx.xx.xxxx. In reply to
As I said before:

Could you post your sub get_date here? There are various versions floating around and I need to see what you have.

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Last modified: xx.xx.xxxx. In reply to
Hi JPD

Thanks for helping

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.

my ($sec, $min, $hour, $day, $mon, $year, $dweek, $dyear, $daylight) = localtime(time());
my (@months) = qw!01 02 03 04 05 06 07 08 09 10 11 12!;
($day < 10) and ($day = "0$day");
$year = $year + 1900;

return "$day.$months[$mon].$year";
}

Cheers

Blech

Quote Reply
Re: Last modified: xx.xx.xxxx. In reply to
Hi! I'm also using the last modified date on my database on the main menu page. I don't know whether this will help you or not but it's defintely working on my database. Each time someone alters my .db file, the new date will be printed out.

This is this subrountine you need to add to your db.cgi :

sub get_date_and_time {
#-----------------------------------------------------------
my ($time) = @_;
($time) || ($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;
($sec < 10) and ($sec = "0$sec");
($min < 10) and ($min = "0$min");
($hour < 10) and ($hour = "0$hour");

# if you want the time returned in "am/pm" # format, uncomment the lines below

# ($hour > 11) ? ($am_pm = "pm") : ($am_pm = "am");
# if ($hour > 12) { $hour -= 12; }
# elsif ($hour < 1) {$hour = 12; }
return "$months[$mon]-$day-$year $hour:$min:$sec $am_pm";
}

Then add the following to the same subroutine you want the date to appear in the html.pl file. Remember to add right at the beginning of the subrountines in html.pl:

$last_mod = &get_date_and_time(time() - ((-M $db_file_name) * 86400));

Then use $last_mod to print the date.

Just to clear things up. I did not write this subroutine. I can't remember where I got it from.

Julian
Quote Reply
Re: Last modified: xx.xx.xxxx. In reply to
Well, vampy gave you one of the many versions that is floating around and it will give you both the time and the date. If you just want the date, change sub get_date to

Code:

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.
my ($time) = @_;
($time) || ($time = time());
my ($sec, $min, $hour, $day, $mon, $year, $dweek, $dyear, $daylight) = localtime($time);
my (@months) = qw!01 02 03 04 05 06 07 08 09 10 11 12!;
($day < 10) and ($day = "0$day");
$year = $year + 1900;

return "$day.$months[$mon].$year";
}
JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Last modified: xx.xx.xxxx. In reply to
Thanks JPD and vampy.

My script is working

Cheers

Serge