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)
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.
function appropriatelyAged(){
$this->Children()->filterByCallback(function($child){
return date_create($child->date)->diff(date_create())->days < 7;
});
}
Thanks