Gossamer Forum
Home : General : Perl Programming :

Changing the formatting of a date.

Quote Reply
Changing the formatting of a date.
In DBMan I have modified the "date_to_unix" sub and created a new one called "date_to_screen". The purpose of this is to modify the date string originally in this format: 03/04/2000
(It is different than the normal format used by DBMan)

to this format: March 4, 2000

But it does not seem to work, can anybody help me debug why it is not doing it correctly?

Code:
sub date_to_screen {
# --------------------------------------------------------
# Comments removed for space considerations.
my ($date) = $_[0];
my (%months) = ("January" => 1, "February" => 2, "March" => 3, "April" => 4,
"May" => 5, "June" => 6, "July" => 7, "August" => 8,
"September" => 9, "October" => 10, "November" => 11,
"December" => 12);
my ($time);
my ($mon, $day, $year) = split(///, $_[0]);
unless ($mon and $day and $year) { return undef; }
unless (defined($months{$mon})) { return undef; }

eval {
$day = int($day); $year = int($year); $mon = int($mon);
$time = '$months{$mon} $day, $year';
};
if ($@) { return undef; } # Could return 0 if you want.
return ($date);
}

Any Ideas?
Quote Reply
Re: Changing the formatting of a date. In reply to
You also need to change the sub get_date routine to match the changes you've made in this new date routine.

BTW: Date format changes have been discussed numerous times in the DBMAN Discussion Forum and Installation Forum where this type of question should be posted.

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
Quote Reply
Re: Changing the formatting of a date. In reply to
This subroutine never calls the date_to_unix routine so I am pretty sure that is not the problem.

The rest of the Story: The datafile is actually generated by another program and I'm actually really only using dbman to display and search all of the results (I know, I know, there's probably better programs to do that, but I really like DBMan)

I'm thinking the problem has something to do with the split() function but am not sure about that. This function's function is only to expand an existing date format into an expanded one for display on the screen.

I appologize if I am indeed in the wrong forum but it seems to me that I have more of a PERL problem than a problem with DBMan so I didn't want to post it there.
Quote Reply
Re: Changing the formatting of a date. In reply to
Since this relates specifically with a code hack of a specific Gossamer Thread script, it should be posted in that specific forum.

That said...the problem is, indeed, with the split codes since you have a space and then a comma between the variables...Try the following:

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

This will split the variables first by space and then the comma.

Hope this helps.

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums