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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

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

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


Go to End


2 Posts   731 Views

Avatar
brandonl

Community Member, 2 Posts

14 July 2012 at 8:36am

Edited: 14/07/2012 8:37am

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

Avatar
brandonl

Community Member, 2 Posts

14 July 2012 at 12:03pm

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 } ?>