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

Automatically insert current date into date field of new pages

Go to End

2 Posts   2371 Views


Community Member, 197 Posts

28 July 2010 at 12:47pm

I use the following code in conjunction with the legacydatetimefields module to allow the administrator to select a date:

      $fields->addFieldToTab("Root.Content.Times", new PopupDateTimeField('RankingDate', 'Ranking Date'));

When a page is create that field is blank. I want the current date to be placed in that field when new pages are created but after the page is created I want the administrator to be able to change it to any date.


Community Member, 344 Posts

28 July 2010 at 7:24pm

Edited: 28/07/2010 7:25pm

public function populateDefaults(){
	$this->RankingDate = date("Y-m-d");