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.

Blog Module /

Discuss the Blog Module.

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

Date Field in Blog Module

Go to End

13 Posts   8727 Views


Community Member, 80 Posts

9 March 2010 at 10:45pm



setlocale(LC_TIME, i18n::get_locale() . ".utf8");

to the function FormatI18N also helped me to solve an "umlaut" - bug with "märz".
thank you,


Community Member, 150 Posts

29 October 2010 at 6:41am

Edited: 30/10/2010 3:14am

I've tried all of the above on an SS2.4.2 install:

Added this in _config.php:

  Object::add_extension('SiteTree', 'Translatable');
  Object::add_extension('SiteConfig', 'Translatable');
  setlocale(LC_TIME, 'nl_NL');

Altered function FormatI18N() in sapphire/core/model/fieldtypes/Date.php:

  function FormatI18N($formattingString) {
    setlocale(LC_TIME, i18n::get_locale() . ".utf8");
    if($this->value) return strftime($formattingString, strtotime($this->value));

Have this in my

  $Date.FormatI18N(%e %B)

And still I get 'October' instead of the Dutch 'oktober'. What am I doing wrong?

PS. $Locale in my does provide me with nl_NL

PPS. It does work on my local MAMP environment. On shared hosting it doesnot work, even with this code (server issue?!):

function FormatI18N($formattingString) {
  setlocale(LC_TIME, i18n::get_locale() . ".utf8");
  setlocale(LC_TIME, 'nl_NL.UTF8');
  if($this->value) return strftime($formattingString, strtotime($this->value));


Community Member, 22 Posts

25 March 2011 at 9:56pm

Edited: 25/03/2011 9:58pm

As it also took me quite some time to get datefields printed in the correct locale (of the visitor), I'll outline how I achieved this (SS2.4.5);

To translate $Date fields for the current locale, first set the correct locale. This code works for me if I put it in the Page_Controller (_config.php seems to be too early):

// mysite/code/Page.php
class Page_Controller extends ContentController {

	public function init() {

		// Set locale for PHP, dates etc;
		setlocale(LC_TIME, Translatable::get_current_locale() . ".UTF8");

		// using i18n::get_locale() didn't seem to work for me;
		// setlocale(LC_TIME, i18n::get_locale() . ".utf8");


Then cast the date to the current locale in your template;

 $Date.FormatI18N(%e %B %Y) 

If this is not working, make sure you add a ?flush=1 to the URL.

Still not working, it could be that the locale is not installed on the server. If you have a shell account, do a

locale -a

This shows you all installed locales. If the needed locale is indeed not installed, you can install it yourself if you have root (Debian/Ubuntu);

 dpkg-reconfigure locales 

And add the neede locale. It should also be possible to install locales in your home directory (as non-root), Google probably knows best...


Community Member, 150 Posts

26 March 2011 at 1:17am

Many thanks, I'll try this myself!


Community Member, 2 Posts

20 April 2013 at 4:19am

Edited: 20/04/2013 4:19am

I have created a small module for SS3 that will translate dates automatically once added to your project. You can check it out here:

Bug reports and improvement suggestions are most welcome!

Go to Top