You can put it in one field if you want to.
Code:
sub get_date {
# --------------------------------------------------------
# Returns the date in the format "Mmmm dd, yyyy hh:mm am/pm".
# 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);
# Expand the month names below
my (@months) = qw!Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec!;
$year = $year + 1900;
if ($hour == 12) { $ampm = "p.m." }
elsif ($hour == 0) { $hour = 12; $ampm = "a.m."; }
elsif ($hour <12) { $ampm = "a.m." }
else { $hour -=12; $ampm = "p.m." }
($min < 10) and ($min = "0" . $min)
return "$months[$mon], $day $year $hour:$min $ampm";
}
Code:
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];
# Expand the month names below
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 ($mon, $day, $year, $time, $ampm) = split(/ /, $date);
$day =~ s/,//;
my ($hour, $min) = split(/:/, $time);
if (($hour == 12) && ($ampm eq "a.m.")) { $hour == 0; }
elsif (($hour<12) && ($ampm eq "p.m.")) { $hour +=12; }
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;
$min = int($min); $hour = int($hour);
$time = timelocal(0,$min,$hour,$day, $months{$mon}, $year);
};
if ($@) { return undef; } # Could return 0 if you want.
return ($time);
}
JPD
http://www.jpdeni.com/dbman/