Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

Handy "nice date" global =)

Quote Reply
Handy "nice date" global =)
Hi,

Heres a handy little global that I thought I'd share. Simply pass in yyyy-mm-dd format, or dd-mm-yyyy [US format] [UK format]), and it will return it in a "nice" format.

For example;

Quote:
2004-01-30

..would show as;

Quote:
30th January 2004.

...and;

Quote:
10-02-2005

..would show up as;

Quote:
10th February 2005

simply call with;

<%global_name($DATE_FIELD)%>

Code:
sub {

my @months = qw/January February March April May June July August September October November December/;
my @dayextensions = qw/1st 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th 13th 14th 15th 16th 17th 18th 19th 20th 21st 22nd 23rd 24th 25th 26th 27th 28th 29th 30th 31st/;

my $date = $_[0];

if ($date =~ /^\d\d\d\d\-\d\d\-\d\d$/) {

my ($yyyy,$mm,$dd) = split /-/, $date;

$mm =~ s/^0//;
$dd =~ s/^0//;

my $dback = $dayextensions[$dd-1];
my $mback = $months[$mm-1];
my $yback = $yyyy;

return qq{$dback $mback $yback}

} else {


my ($dd,$mm,$yyyy) = split /-/, $date;

$mm =~ s/^0//;
$dd =~ s/^0//;

my $dback = $dayextensions[$dd-1];
my $mback = $months[$mm-1];
my $yback = $yyyy;

return qq{$dback $mback $yback}


}

}

Hope that helps someone :)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Subject Author Views Date
Thread Handy "nice date" global =) Andy 7049 Oct 17, 2005, 12:42 AM
Post Re: [Andy] Handy "nice date" global =)
aus_dave 6925 Oct 17, 2005, 5:55 AM
Thread Re: [Andy] Handy "nice date" global =)
goman 6881 Oct 20, 2005, 12:58 PM
Thread Re: [goman] Handy "nice date" global =)
Andy 6887 Oct 20, 2005, 11:59 PM
Thread Re: [Andy] Handy "nice date" global =)
Eraser 6488 Oct 18, 2009, 5:21 AM
Thread Re: [Eraser] Handy "nice date" global =)
Eraser 6461 Oct 18, 2009, 5:35 AM
Post Re: [Eraser] Handy "nice date" global =)
Andy 6468 Oct 18, 2009, 5:41 AM
Thread Re: [Andy] Handy "nice date" global =)
VishalT 6467 Oct 18, 2009, 6:18 AM
Thread Re: [SWDevil.Com] Handy "nice date" global =)
MJB 6295 Jan 22, 2010, 7:21 AM
Post Re: [MJB] Handy "nice date" global =)
MJB 6286 Jan 22, 2010, 7:25 AM