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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

$Now not available in dataobject


Go to End


1211 Views

Avatar
Bronwyn

Community Member, 22 Posts

28 February 2013 at 4:29pm

Edited: 01/03/2013 10:06am

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