Hey guys,

I need a little help with some code im working on.
In the end I want some code to change the visible text when dates are past, my current code is below, but this only works for one date. I would like it to update to the next date in a calendar when the date passes.


$nextEvent = "2012-06-23 21:00:00";
$dateEventAfterNext = "30th June 2012";
$dateNextEvent = "23rd June 2012";

if( strtotime($nextEvent) < time() ){ // date format is YYYY-MM-DD
echo $dateEventAfterNext;
echo $dateNextEvent;

Any ideas guys?


Member Avatar

Does this have to be real-time or can it just work on page load. What I mean is, should the changes occur as you're watching the screen or can they be set when the page is first rendered, and you only see the difference when the page is reloaded?

They can occur on page load.

Let me rephrase the question.

Im trying to display the date of the next event.
When this date passes, it moves onto the next date etc.

For example, if today is the 23rd June, and the next event is on the 26th June, on the 26th June at 21:00 the date of the next event will be shown.

At the moment, I just have this code that works for one week, and will require me to change the $nextevent date. Im looking for some method of inputting the dates into a MySQL table for example, and then the php reading that information onto the page.


$nextEvent = "2012-06-23 21:00:00";

if( strtotime($nextEvent) < time() ){
//when date has past
//when date hasnt past


Any Ideas?


Member Avatar

Save dates to mysql - you need help on that?
Should be straightforward:

$result = mysql_query("INSERT INTO table (...) VALUES (...)");

Retrieving the latest event - if you're changing on 21:00:

$today = date('Y-m-d');
$op = (date('H:i') >= '21:00') ? ">" : ">=";
$result = mysql_query("SELECT ... FROM table WHERE mydate $op '$today' ORDER BY mydate LIMIT 1"); 
//then use mysql_num_rows and mysql_fetch_assoc

Sorry, just re-read your post - saw the date format:

$time = date("Y-m-d H:i:s);
$result = mysql_query("SELECT ... FROM table WHERE mydate > '$time' ORDER BY mydate LIMIT 1");