3060 Posts in 864 Topics by 646 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 2132 Views |
-
DataObject compare date

1 March 2009 at 5:17am
Hello,
I creating a event-list module. Now I want to show the next five events on every page. But I have a problem to filter only events in future. This way does not work:
function NextEvents($num=5) {
$timestamp=time();
$datetoday=date("Y-m-d",$timestamp);
$events = DataObject::get_one("eventholder");
return ($events) ? DataObject::get("event", "date > $datetoday", "", $num) : false;How can I compare the event-date with the current date?
-
Re: DataObject compare date

2 March 2009 at 3:02am
No idea??
The query works perfectly for all records. But how can I get only records with a date in future? -
Re: DataObject compare date

2 March 2009 at 8:31am Last edited: 2 March 2009 8:31am
The where clause is MySQL. MySQL has a function CURDATE() that returns the current date, so you don't need to generate it yourself. Also, 'date' is a reserved sql word, so you'll need to escape it with backticks.
This should work (not tested - but refer to MySQL documentation for further info):
return ($events) ? DataObject::get("event", "`date` > CURDATE()", "", $num) : false;
-
Re: DataObject compare date

2 March 2009 at 9:10am
Thanks for the answer, but it does not work. There is still the error "Couldn't run query [...] right syntax to use near '5 WHERE (`date` > CURDATE()) AND (`SiteTree_Live`.ClassName IN ('event')) GROUP' at line 1"
How does it work??
-
Re: DataObject compare date

2 March 2009 at 10:22am
return ($events) ? DataObject::get("event", "`date` > CURDATE()", "", $num) : false;
should be changed to
return ($events) ? DataObject::get("event", "`date` > CURDATE()", "", "", $num) : false;
| 2132 Views | ||
|
Page:
1
|
Go to Top |



