21309 Posts in 5738 Topics by 2603 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 233 Views |
-
get dates later than today

8 January 2013 at 5:34pm
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 -
Re: get dates later than today

9 January 2013 at 1:40am Last edited: 10 January 2013 2:06am
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.
-
Re: get dates later than today

9 January 2013 at 5:24am
I think you can still use where, something like:
ArticlePage::get()->filter(array('ParentID' => $holder->ID))->where("Date >= CURDATE()")->sort('Date DESC');
Martine
-
Re: get dates later than today

9 January 2013 at 7:13pm
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!
| 233 Views | ||
|
Page:
1
|
Go to Top |


