Page 1 of 1

Help with date activated content, not database

Posted: Mon Aug 07, 2006 9:39 am
by Diggler
I am new to PHP but not web programming. I have a website for my band, where I'd like content to switch after a certain date and time. For example, if I have an event scheduled for 8/15/2006 that ends at 11pm, and another one that is on 8/27/2006, I would like to use an if/else statement to check the date and echo out the appropriate content:

Until 11pm on 8/15, the first event content will display. At 11:00:01 pm on 8/15, the content of the event for 8/27 will display instead.

I know I could easily do this with a database, but I'd like a quick and dirty method to implement until I get time to design and develop it properly. It doesn't need to handle more than two dates, I just need it to do the single switch until I can get home and tweak it for the next upcoming date.

TIA

Posted: Mon Aug 07, 2006 11:06 am
by blackbeard
You can try something like this:

Code: Select all

$firstEventTime = mktime (23, 00, 00, 08, 15, 2006)  //  Hour, minute, second, month, day of month, year

if (time() <= $firstEventTime) {  //  if the current time is before the first event

/*

First event content

*/
}
else {

/*

Second event content

*/
}

Thanks...

Posted: Mon Aug 07, 2006 6:15 pm
by Diggler
Thanks for your help. That almost gets it for me. But for some reason, it doesn't seem to be working as expected.

Code: Select all

// 2am, on Aug. 19, 2006:
$firstEventTime = mktime (02, 00, 00, 08, 19, 2006);  //  Hour, minute, second, month, day of month, year

if (time() <= $firstEventTime)   //  if the current time is before the first event
{
echo "time: " . time();
echo "<br>";
echo "firstEventTime: " . $firstEventTime;
echo "<br>Original Content";
}
else
{
echo "time: " . time();
echo "<br>";
echo "firstEventTime: " . $firstEventTime;
echo "<br>Changed Content";
}
I ran this around 7:11 pm tonight, on Aug. 7, 2006. The following is what I got out on the screen:

Code: Select all

time: 1154992252
firstEventTime: 1134975600
Changed Content
Why would the time be less than the firstEventTime? I would expect the time to be less than firstEventTime, and for Original Content to show until 2am on Aug. 19. Am I missing something?

Thanks again!

Posted: Mon Aug 07, 2006 6:18 pm
by litebearer
php is most likely calculating the time based upon server time as opposed to your local time. You need to compensate for the difference between server time and local time

Posted: Mon Aug 07, 2006 6:24 pm
by Diggler
But 12 days difference? I use the function to get the last modified date for my pages and it works fine...