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

How to create form to search events between two dates?


Go to End


4 Posts   1165 Views

Avatar
VPull

Community Member, 58 Posts

15 February 2016 at 7:00pm

Hello Guys
I wanted to create search event form on website front end, so my user can search events by entering two date (from and to).
I have created class called events which have fields (Title, StartDate, EndDate).
I already followed steps mention here but I am
not able to modified as per my requirement. Please help me to find out quick solution.
Thanks in advance.

Avatar
nzstephenf

Community Member, 63 Posts

16 February 2016 at 12:17am

Edited: 16/02/2016 12:41am

Hey VPull,

Here's a way to get you going..

public function yourfunction(){
    $event = Event::get();
    $startdate = "2016-02-15"; /** so this would be $data["StartDate"]; **/
    $enddate = "2016-02-20"; /** this would be $data["EndDate"]; **/
    $event = $event->where('("Event"."StartDate" >= \'' .date('Y-m-1', $startdate). '\' AND "Event"."EndDate" <= \'' .date('Y-m-t', $enddate). '\')');

    return $event;
}

Avatar
VPull

Community Member, 58 Posts

16 February 2016 at 1:15am

Edited: 16/02/2016 1:23am

Thanks for you reply, but this code does not work with my requirement.

Avatar
Mildy

Community Member, 3 Posts

17 March 2016 at 3:42am

The easiest way often takes a long time to come up to.
Thank you for providing a code. I needed it.