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.

Template Questions /

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

A solution to getting your date and time in your locale

Go to End



Community Member, 203 Posts

2 August 2013 at 3:38am

My example is based on German and Silverstripe 3.

When you have a datefield in your cms that you use to set a date and you want to set the date in a locale different from en_US. In your controller add the function:

function localDate($myDate) {
	$newLocale = setlocale(LC_TIME, 'de_DE', 'de_DE.UTF-8');
	return strftime('%d. %B %Y', strtotime($myDate));

In your template use $localDate($myDateField) and you are golden.

Change the de_DE to your own locale. Change '%d. %B %Y' to something that looks nice to you:

When getting the time from a DateTimeField use $myDateTime.Time24() in your templates together with the localDate() function because there seems to be a problem with getting the minutes.