Help with date activated content, not database

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Diggler
Forum Newbie
Posts: 3
Joined: Mon Aug 07, 2006 9:29 am

Help with date activated content, not database

Post 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
blackbeard
Forum Contributor
Posts: 123
Joined: Thu Aug 03, 2006 6:20 pm

Post 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

*/
}
Diggler
Forum Newbie
Posts: 3
Joined: Mon Aug 07, 2006 9:29 am

Thanks...

Post 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!
Last edited by Diggler on Mon Aug 07, 2006 6:47 pm, edited 1 time in total.
litebearer
Forum Contributor
Posts: 194
Joined: Sat Mar 27, 2004 5:54 am

Post 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
Diggler
Forum Newbie
Posts: 3
Joined: Mon Aug 07, 2006 9:29 am

Post by Diggler »

But 12 days difference? I use the function to get the last modified date for my pages and it works fine...
Post Reply