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
Help with date activated content, not database
Moderator: General Moderators
-
blackbeard
- Forum Contributor
- Posts: 123
- Joined: Thu Aug 03, 2006 6:20 pm
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...
Thanks for your help. That almost gets it for me. But for some reason, it doesn't seem to be working as expected.
I ran this around 7:11 pm tonight, on Aug. 7, 2006. The following is what I got out on the screen:
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!
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";
}Code: Select all
time: 1154992252
firstEventTime: 1134975600
Changed ContentThanks 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