Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Archive /

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo

Formatting Dates

Go to End

5 Posts   2972 Views


Community Member, 14 Posts

23 April 2008 at 12:55am

Edited: 23/04/2008 12:56am


We just solved a problem for us that I think all non-English users of silverstripe have: The Date Fieldtype uses the php function date(), which does not respect the setlocale settings:

if($this->value) return date($formattingString, strtotime($this->value));

Output: "February 2008" on a German computer.

Instead we use strftime:

if ($this->value) return strftime($formattingString, strtotime($this->value));

Output: "Februar 2008".

Is there any matter why date() is used? Otherwise I would propose to change this or to add a function strftime.




Administrator, 690 Posts

23 April 2008 at 1:55pm

This seems like a reasonable change. Can you submit a patch to


Community Member, 14 Posts

23 April 2008 at 7:40pm

Yes, of course! As this is my first patch for silverstripe: This is a Patch for "Core" against the trunk (aka 2.2.2RC3) for Milestone 2.2.3, component "Sapphire Framework", right? I will check, whether there are other places where date() is used.

Ah, what do you prefer? A general change towards strftime would require to change any format strings, as the syntax is different ("d.m.Y" vs. "%d.%m.%Y"). I still would prefer this as the standard way to format dates in silverstripe should be localized (hmm, does the word "localizable" exist?). I would track all uses of format strings in the core and in modules (I think mainly the blog module) and change them.

The alternative would be an additional function strftime().




Community Member, 1 Post

7 June 2008 at 11:28am

A better solution would probaply be just adding a function called "LocalFormat" or something, which would wrap strftime as described.
This wouldn't break compatibility and features like pre-formatted ISO dates (which strftime doesn't currently supply) wouldn't be gone.


Community Member, 14 Posts

27 September 2008 at 2:30am

Thank you very much your code helped a lot but,
I think you should consider to add a utf8_encode() this way:

function LocalFormat($formattingString) {
		if($this->value) return utf8_encode(strftime($formattingString, strtotime($this->value)));

because it helps for french language