The original DBMan script has the date as 01-May-2000. I want the date to be 05/01/2000. I have coded the 'sub get_date' to give me the 05/01/2000. But when I go to add a record, the validate routine can't convert the date back to unix time and gives me back an error on the date field. Here is my 'sub date_to_unix:
#------------------------------------
my ($date) = $_[0];
my ($time);
my ($mon, $day, $year) = split(/\//, $_[0]);
unless ($day and $mon and $year) { return undef; }
use Time::Local;
eval {
$mon = int($mon) - 1; $day = int($day); $year = int($year) - 1900;
$time = timelocal(0,0,0,$day, $mon, $year);
};
if ($@) { return undef; } # Could return 0 if you want.
return ($time);
}
As you can see, I have changed the
my ($day, $mon, $year) = split(/-/, $_[0]);
to
my ($mon, $day, $year) = split(/\//, $_[0]);
and changed the $mon in eval to
$mon = int($mon) - 1;
Any suggestions?
AJ
Code:
sub date_to_unix { #------------------------------------
my ($date) = $_[0];
my ($time);
my ($mon, $day, $year) = split(/\//, $_[0]);
unless ($day and $mon and $year) { return undef; }
use Time::Local;
eval {
$mon = int($mon) - 1; $day = int($day); $year = int($year) - 1900;
$time = timelocal(0,0,0,$day, $mon, $year);
};
if ($@) { return undef; } # Could return 0 if you want.
return ($time);
}
As you can see, I have changed the
my ($day, $mon, $year) = split(/-/, $_[0]);
to
my ($mon, $day, $year) = split(/\//, $_[0]);
and changed the $mon in eval to
$mon = int($mon) - 1;
Any suggestions?
AJ