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:

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

I need CMS DateField to only show date, not time.

Go to End

2 Posts   1261 Views


Community Member, 165 Posts

30 August 2009 at 11:59am

Edited: 30/08/2009 12:02pm

If I have a $db 'Date' => 'Date' and then in getCMSFields() I have new DateField('Date'), it shows the date and time. I want it to only show the date because there is no time needed.

Note: I just noticed that the Database field type was datetime so I changed it to date and that fixed the issue.


Community Member, 271 Posts

30 August 2009 at 1:32pm

Edited: 30/08/2009 1:36pm

But still sometimes you want to store date in datetime format, but in one situation only display them in DD-MM-YYYY and in another situation in DD-MM-YYYY HH:MM.

I couldn't find any SS build in solution, so I think creating a method in your controller will fix the issue:

function Nicedate(){
	$datetime = new DateTime($this->YourDateTimeField); // >= php 5.2
	return $datetime->format('jS, F Y'); // or d-m-Y