Jump to:

23374 Posts in 18175 Topics by 2866 members

General Questions

SilverStripe Forums » General Questions » Swaiba or Anyone - How to Display Content at a Certain Time

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

Page: 1
Go to End
Author Topic: 341 Views
  • brandonl
    Avatar
    Community Member
    2 Posts

    Swaiba or Anyone - How to Display Content at a Certain Time Link to this post

    Swaiba,

    I mentioned your name because you previously posted code similar to what I need. Someone asked how to display content on a certain day. How can I modify your answer to display content at a certain time, such as 7:00 PM?

    Your answer to displaying content on a certain day:

    public function Content() {
    $content = $this->getField('Content');

    if (date('N')==1) { //if Monday
    $content = 'It is Monday you get this string instead';
    }

    return $content;
    }

    Brandon

  • brandonl
    Avatar
    Community Member
    2 Posts

    Re: Swaiba or Anyone - How to Display Content at a Certain Time Link to this post

    I found the answer:

    <?php
    $end_date = strtotime('02:00pm April 1, 2012');
    $now = time();
    if ($end_date < $now) {
    ?>
    Updated content
    <?php } else { ?>
    Older content
    <?php } ?>

    341 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.