tags:

views:

22

answers:

1

I have this code to capture a date and time:

date('F j, Y, g:i a T')

and save is as

$datetime:

and I have this code to include a template:

function template_contents($file, $model) {
    if (!is_file($file)) {
        throw new Exception("Template not found");
    }
    ob_start();
    include $file;
    $contents2 = ob_get_contents();
    ob_end_clean();

    return $contents;
}

if($datetime == "No Date Yet"){
    echo template_contents("post.php", $model);
} elseif($datetime == "June 2, 2010, 2:55 pm MDT"){
    echo template_contents("notpost.php", $model);
}else {
    echo template_contents("post.php", $model);
}

And I as hoping to edit the elseif statement to show the notpost.php template if the $datetime was less than 2 days. So, notpost.php shows up for two days and post.php shows up after two days. What would be an easy way to do this?

+1  A: 

Change the elseif statement to:

} elseif (time() <= strtotime("June 2, 2010, 2:55 pm MDT")) {

This shows notpost.php if the current time (given by time()) is earlier than the given time.

phsource
Worked great. Thanks!
Jon