Gossamer Forum
Home : Products : DBMan : Customization :

Help with date for auto delete

Quote Reply
Help with date for auto delete
Today I found why my Auto Delete is mod is not working...

actually I did change the time for &get_date; because I need this to be in such format to insert into the database.

Current format: Aug-05-03

#####################

sub
get_date {

# Warning: If you change the default format, you must also modify the &date_to_unix, HOW?????


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
"$months[$mon]-$day-$year";
}


#######################



But for Auto Delete

my
$today = &date_to_unix(&get_date);

I never changed the &date_to_unix;

########################

Now my question is what changes should be made to &date_to_unix;

to work along with current date format i.e. Aug-05-03

I am also posting unchanged sub date_to_unix

#######################

sub
date_to_unix {
my ($date) = $_[0];
my (%months) = (
"Jan" => 0, "Feb" => 1, "Mar" => 2, "Apr" => 3, "May" => 4, "Jun" => 5,
"Jul" => 6, "Aug" => 7, "Sep" => 8, "Oct" => 9, "Nov" => 10,"Dec" => 11);
my ($time);
my ($day, $mon, $year) = split(
/-/, $_[0]);
unless ($day and $mon and $year) { return undef; }
unless (defined($months{$mon})) { return undef; }

use Time::Local;
eval {
$day = int($day); $year = int($year) - 1900;
$time = timelocal(0,0,0,$day, $months{$mon}, $year);
};
if ($@) { return undef; }
# Could return 0 if you want.
return ($time);
}


#############################



Thanks for any input,



Zeshan.


Quote Reply
Re: [zeshan] Help with date for auto delete In reply to
The lines:

return "$months[$mon]-$day-$year";

and

my ($day, $mon, $year) = split(/-/, $_[0]);

must match. try using:

my ($mon, $day, $year) = split(/-/, $_[0]);

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [LoisC] Help with date for auto delete In reply to
Thank you very much for your input.

One more question is

"Can I put the two variables for &auto_delete:

my $remove = 1;
# Number of days old.
my $date_field = 8;
# Position of date field.

in the default.cfg rather than in db.cgi?

I will be will be changing $remove frequently, so I think its easy to update the default.cfg than db.cgi every time.


Quote Reply
Re: [zeshan] Help with date for auto delete In reply to
If it's just the variable .. I should think it would be okay to have it defined within your .cfg file.

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/