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.

Data Model Questions /

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

Expires.InPast not working right

Go to End

4 Posts   1832 Views


Community Member, 49 Posts

22 October 2009 at 9:02pm

I've been trying to make the InPast function to work.

$Expires.InPast outputs 1 when its out of date, but when I run a <% if Expires.InPast %>..<% end_if %> it doesn't to anything with it and shows every article..

Any idea why or what I'm doing wrong?


Community Member, 66 Posts

26 November 2009 at 7:33am

I am banging my head against the wall on this problem, too!

Did you find a solution? If so, I would be very interested in what you came up with! Thanks in advance.


Community Member, 80 Posts

7 December 2009 at 8:59am

I have this problem too!


Community Member, 253 Posts

7 December 2009 at 1:10pm

Hmmm... Lots of people seem to be having trouble getting this to work. I never have needed to use it, so I can't say from experience where the issue lies. However, i do have a solution.

Simply, when you do this on an item, it will be a property of a DataObject, so we can simply build a method into the model called 'hasExpired'.

Simply in the model we need to create a method:

class Page extends SiteTree {
    public function hasExpired() {
        return (strtotime($this->Date) < time());

Now, in your template you can do:

<% if hasExpired %>
<% end_if %>

Obviously 'Date' will have to be declared in the $db array with date type

I hope that helps