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.

General Questions

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

get dates later than today


Reply

4 Posts   854 Views

Avatar
Bruce B

8 January 2013 at 5:34pm Community Member, 145 Posts

I hate it when simple things trip you up. In my SS2.4 site I had the following line to collect all future events pages:

$littlechildren = DataObject::get("ArticlePage", "ParentID = $this->ID and Date >= CURDATE()", "Date ASC", null, null);

In SS3, I have this:

$holder = ArticleHolder::get()->filter('URLSegment', 'meetings')->first();
return ($holder) ? ArticlePage::get()->filter(array('ParentID' => $holder->ID,'Date:GreaterThan' => '2013-01-07'))->sort('Date DESC') : false;

I'd like to replace the string '2013-01-07' with CURDATE() but SS3 does not like CURDATE() in that context and considers it an undefined function.

What's the best solution?

cheers
bruce

Avatar
IOTI

9 January 2013 at 1:40am (Last edited: 10 January 2013 2:06am), Community Member, 189 Posts

Maybe not the best solution, but you could use PHP date function to figure out the current date and use it in place of your hard coded "2013-01-07", something like

$curDate = date("Y-m-d");

$holder = ArticleHolder::get()->filter('URLSegment', 'meetings')->first();
return ($holder) ? ArticlePage::get()->filter(array('ParentID' => $holder->ID,'Date:GreaterThan' => $curDate))->sort('Date DESC') : false;

edit* - added missing quotes around (Y-m-d). Thanks for pointing out Bruce.

Avatar
martimiz

9 January 2013 at 5:24am Forum Moderator, 1091 Posts

I think you can still use where, something like:

ArticlePage::get()->filter(array('ParentID' => $holder->ID))->where("Date >= CURDATE()")->sort('Date DESC');

Martine

Avatar
Bruce B

9 January 2013 at 7:13pm Community Member, 145 Posts

I can now report that both methods work just fine. I think I'll go with IOTI's version as it seems a little more in keeping with the SS 3 'vibe'. The only change required is that the first line should include quotes:

$curDate = date("Y-m-d");

I'll file martimiz's version away for future problems.

Thanks heaps guys for the quick responses!