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

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


Reply


2 Posts   395 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 } ?>