I wish to modify the date format to use mm/dd/yyyy. My modification seemed to be working, but I have discovered that I cannot enter a date prior to 1970 (the operation times out when I try to save the record). Below is the code (any help would be appreciated!):
sub date_to_unix {
# --------------------------------------------------------
# This routine must take your date format and return the time a la UNIX time().
# Some things to be careful about..
# int your values just in case to remove spaces, etc.
# catch the fatal error timelocal will generate if you have a bad date..
# don't forget that the month is indexed from 0!
#
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]);
my ($mon, $day, $year) = split("/", $_[0]);
unless ($day and $mon and $year) { return undef; }
# unless (defined($months{$mon})) { return undef; }
use Time::Local;
eval {
$mon = int($mon);
$day = int($day);
$year = int($year)- 1900;
# $time = timelocal(0,0,0,$day, $months{$mon}, $year);
$time = timelocal(0,0,0,$day, $mon, $year);
};
if ($@) { return undef; } # Could return 0 if you want.
return ($time);
}
sub date_to_unix {
# --------------------------------------------------------
# This routine must take your date format and return the time a la UNIX time().
# Some things to be careful about..
# int your values just in case to remove spaces, etc.
# catch the fatal error timelocal will generate if you have a bad date..
# don't forget that the month is indexed from 0!
#
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]);
my ($mon, $day, $year) = split("/", $_[0]);
unless ($day and $mon and $year) { return undef; }
# unless (defined($months{$mon})) { return undef; }
use Time::Local;
eval {
$mon = int($mon);
$day = int($day);
$year = int($year)- 1900;
# $time = timelocal(0,0,0,$day, $months{$mon}, $year);
$time = timelocal(0,0,0,$day, $mon, $year);
};
if ($@) { return undef; } # Could return 0 if you want.
return ($time);
}