Create a function to sort and return bye date

silverstripe-4
Tags: #<Tag:0x00007f10cf1d4048>

#1

In ss4, i defined a start_date variable in kind of pages, and we need a function that return and sort Only between now and 14 days after start_date, in the other words i need the pages only between:
Start_date < selected page < Start_date + 14
and
End_date < selected page < End_date - 14
(2 weeks after start and two weeks before end)


#2

You can use the SilverStripe search filter modifiers for this:

https://docs.silverstripe.org/en/4/developer_guides/model/searchfilters/#searchfilter-modifiers

So you would calculate the start and end of the period and then have something like:

$pages = YourPageClass::get()->filter([
  'PageDate:GreaterThanOrEqual' => $startTime,
  'PageDate:LessThanOrEqual' => $endTime
])->sort('PageDate');

#3

I think that i need to explain more for the function that i need, I creat a TheartePage that contain:

private static $db = [
        'StartDate' => 'Date',
        'FinishDate' => 'Date',
    ];

and i want to loop in a page (FirstWeek) for two weeks from StartDate & a page to loop to weeks untill FinishDate (LastWeek) (According to today {$Now})
(e.g. StartDate=2018,11,01 & FinishDate=2019,03,15)
(if the today=2018,11,05{$Now} loop the in FirstWeek & if today{$Now}=2019,03,12 shown in LastWeek)