Gossamer Forum
Home : Products : DBMan : Customization :

mm/dd/yyyy 1970 date problem

Quote Reply
mm/dd/yyyy 1970 date problem
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);

Quote Reply
Re: mm/dd/yyyy 1970 date problem In reply to
Right. The problem is that the script uses the Unix date, which starts on 1 Jan 1970, to determine whether the date is in the correct format. Since any date before then can't be translated into a Unix date, it should return a -1.

I'm not sure why your database times out when you try it, though.

I've just written a mod that's a "universal date translator" which also should allow you to enter any date from 1 Jan 1000 through 31 Dec 9999. It should sort dates and find "-gt" and "-lt" dates that are before 1970. However, I haven't had a chance to actually test it, other than checking for syntax errors. Would you be willing to be my guinea pig?


Quote Reply
Re: mm/dd/yyyy 1970 date problem In reply to
Yes, I would gladly try it.
Quote Reply
Re: mm/dd/yyyy 1970 date problem In reply to
Okay. You can pick up that mod at http://www.jpdeni.com/dbman/Mods/date_translator.txt

If you try it (or anyone else does), be sure to back up your files first.

And please let me know how it works! If you have any problems, I need to know as much detail as possible.