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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

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

Not showing old pages


Go to End


3 Posts   804 Views

Avatar
MCK

Community Member, 18 Posts

19 March 2015 at 10:58am

I have searched high and low for this, and no doubt it is easy, but I would like to only show child pages if they are less than 7 days old. I have created a date field for the child page, etc., but how do I do maths on the date field easily, e.g.,
<% if $Date > ($Date.Now - 7 days) %> ... <% end_if %>
(I know I won't be able to do this in the template but it is easier to show the logic here than attempting to show the idea in PHP—at least for me it is)

Avatar
Pyromanik

Community Member, 419 Posts

20 March 2015 at 11:45pm

function appropriatelyAged(){
	$this->Children()->filterByCallback(function($child){
		return date_create($child->date)->diff(date_create())->days < 7;
	});
}

Avatar
MCK

Community Member, 18 Posts

23 March 2015 at 2:51pm

Thanks