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

EventPage sorted by date - howto show only until today?

Go to End

3 Posts   2092 Views


Community Member, 63 Posts

22 February 2011 at 5:00am


I have a problem with sorting by date...perhaps someone can help me out?

I have a EventHolder and a EventPage

in EventHolder.php i am sorting AllChildren() by a Date field

	function SortedChildren(){
	   $children = $this->AllChildren();	
	   if( !$children )
	      return null;
	   $children->sort('Date', 'ASC');	
	   return $children;

in i list those EventPages

<% control SortedChildren %>
     <h2><a href="$Link">$Date.Format(d.m.Y) - $Title</a></h2>
     <p>$Content.FirstParagraph<a class="arrow" href="$Link">weiter</a></p>
<% end_control %> 

Now i want only to show EventPages with future dates. Old events should no longer be listed wen they are in the past.

Any idea?

Thanks much!


Bruce B

Community Member, 164 Posts

23 February 2011 at 5:07pm

Try this:

function AllFutureChildren() {
$littlechildren = DataObject::get("EventPage", "Date >= CURDATE()", "Date ASC", null, null);
return $littlechildren;

add it to page.php so its accessible from all pages on the site.


Community Member, 63 Posts

14 March 2011 at 11:30pm

Thanks Bruce B ;-)

Works like a charm.