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!
Quote Reply
Re: [Andy] Handy "nice date" global =) In reply to
That looks pretty good Andy. Ordinals in dates are basic with PHP but I haven't known where to start to get them working with Links.

This global will give me something solid to work with Cool.
Quote Reply
Re: [Andy] Handy "nice date" global =) In reply to
Andy, this global is returning the date wrong!!!

--------------------
31st December
--------------------
Quote Reply
Re: [goman] Handy "nice date" global =) In reply to
What format are you passing in? Wink

Its either: yyyy-mm-dd or dd-mm-yyyy

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!
Quote Reply
Re: [Andy] Handy "nice date" global =) In reply to
Hey Andy,

This is rather old, but your global does indeed just show 31st December each time.

Did you ever fix this or have somthing similar?

Have the build date output from this global would be incredible too!

Thanks.

~ ERASER


Free JavaScripts @ Insight Eye

Last edited by:

Eraser: Oct 18, 2009, 5:34 AM
Quote Reply
Re: [Eraser] Handy "nice date" global =) In reply to
Ahh I see - a typo in the instructions :)

<%global_name($DATE_FIELD)%>

should be ...

<%global_name(DATE_FIELD)%>

~ ERASER


Free JavaScripts @ Insight Eye
Quote Reply
Re: [Eraser] Handy "nice date" global =) In reply to
Mmm, it shouldn't work without the $, as thats telling the global its a varialble =)

The code should work fine.

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!
Quote Reply
Re: [Andy] Handy "nice date" global =) In reply to
How did I missed this one... nice global Andy.

Vishal
-------------------------------------------------------
Quote Reply
Re: [SWDevil.Com] Handy "nice date" global =) In reply to
I've tried it with <%clean_date($Add_Date)%> and <%clean_date($Mod_Date)%> but the month is stuck on December. The date and year changes but not the month.
Quote Reply
Re: [MJB] Handy "nice date" global =) In reply to
Right, I looked at the global again and checked out the date format. It only works if you have your Date Options in the control panel set to %dd%-%mm%-%yyyy% but mine were set as %dd%-%mmm%-%yyyy%. Once I changed that it worked OK.