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.

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   2351 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, 343 Posts

28 July 2010 at 7:24pm

Edited: 28/07/2010 7:25pm

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