Gossamer Forum
Home : Products : Gossamer Links : Version 1.x :

Date Display

Quote Reply
Date Display
I managed to locally diplay the date in the format Apr 7 by inserting this code into the HTML_Templates.pm

sub convert_date {
# ---------------------------------------
my $in = shift;
my %months = qw!1 Jan 2 Feb 3 Mar 4 Apr 5 May 6 Jun 7 Jul 8 Aug 9 Sep 10 Oct 11 Nov 12 Dec!;
my ($year, $mon, $day) = split /-/, $in;
return "$months{int $mon} $day";
}

However, recently I changed the Add_Date field Type to DATETIME. Now the page dispalys Apr 7 10:04:38

If anyone has any ideas on how I can cut the 10:04:38 from dispaying, much appreciated.
Thanks.
Quote Reply
Re: Date Display In reply to
When you get the datetime field out of the database, split it on the white space, and put it back together in the format you want, then send it to the template that way.

Quote Reply
Re: Date Display In reply to
If possible, could you post me the code to that modification. Been working on it but can't get it.

Thanks for your help.

Brian
Quote Reply
Re: Date Display In reply to
Sorry to bother you, I know you guys are busy, but I've spent the last several days trying working on this code modification but with no luck... this is the last step to get my things up and running.. could you please post the code for me???
Quote Reply
Re: Date Display In reply to
Looking at your subroutine, the reason what is happening, is happening, is because you are parsing out 3 items, and since there is now "more" data in the string, it gets dumped into the 3rd item, which is the day.

"YYYY-MM-DD HH:MM:SS" is being split into 3 pieces: "YYYY", "MM", "DD HH:MM:SS"

Did you try:

my ($year, $mon, $day) = split /(-|\s)/, $in;

It's a shot in the dark, but if it works, it's the simplest solution for what's ailing you.


[This message has been edited by pugdog (edited April 13, 2000).]
Quote Reply
Re: Date Display In reply to
Thanks for your help, finally got it:

sub convert_date {
# ---------------------------------------
my $in = shift;

my %months = qw!1 Jan 2 Feb 3 Mar 4 Apr 5 May 6 Jun 7 Jul 8 Aug 9 Sep 10 Oct 11 Nov 12 Dec!;
my ($year, $mon, $day) = split /-|\s/, $in;

return "$months{int $mon} $day";
}
Quote Reply
Re: Date Display In reply to
I'm always scared when one of my regexes works <G>