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

$Now not available in dataobject


Reply

279 Views

Avatar
Bronwyn

28 February 2013 at 4:29pm (Last edited: 1 March 2013 10:06am), Community Member, 20 Posts

Hi, I'm trying to use something like
<% if InFuture(EndDate) %> or <% if EndDate.InFuture %>
inside a control to get the next few events to put on a home page.

The control is calling upcoming events, which are defined by this function:

function UpcomingEvents($num=3) {
return DataObject::get("EventObject", "", "StartDate DESC", "", $num);
}

Nothing works.

If I put $Now outside my <% control %> block I get today's date, but anywhere inside it I get nothing. I have come to the conclusion that today's date is just not available to use within my control, which means that I can't use it to tell whether or not things are in the future.

My control is running through objects, not pages.

What I think I might have to do is incorporate it into the function up there^ but my function writing skills are minimal and I don't know how. I need to put in a filter I think.

Any help would be much appreciated.

Edit: I think I've found it. This post was very helpful - don't know why I couldn't find it before http://www.silverstripe.org/data-model-questions/show/12646