3093 Posts in 875 Topics by 654 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1417 Views |
-
Date Filter Difficulties

28 May 2010 at 12:05pm
I have a series of news items saved in my database, each with a startDate and endDate. I'm trying to figure out how to write the filter condition to get all current news item (i.e., those where startDate <= Now and endDate > Now. I've looked around for an example to emulate, but without success.
Here's what I have so far...
class HomePage_Controller extends Page_Controller {
function HomePageNews() {
return DataObject::get('NewsItem', [date filter goes here], 'ID DESC');
}
}Any assistance on writing the date filter would be most appreciated. Thanks.
Cheers,
Laurie -
Re: Date Filter Difficulties

28 May 2010 at 1:27pm
The date fields are date time stamps so you can do something like the following... should work
$now = date('Y-m-d H:i:s');
$where = "startDate <= '$now' AND endDate > '$now'";
I think should work fine (but haven't tested it)
| 1417 Views | ||
|
Page:
1
|
Go to Top |



