Jump to content

Limiting Display of Dates based on Current Date


DDmUSA

Recommended Posts

I would like to know the best practice to achieve the following:

 

I have a list of dates related to live events for performing artists.  When someone views the web page that contains a section to display the dates, I would only want to show the dates from today into the future and not show any dates from the past.

 

What is the best way to accomplish this?

 

Thanks in advance...

Link to comment
Share on other sites

This is for when ur date are in db

 

<?php

$sql = mysql_query("SELECT date FROM table");

while($results == mysql_fetch_query($sql)){

if($results[0] > now()){
// show date
echo $results[0];
}

}
?>

Link to comment
Share on other sites

The following queries will get only the rows with the date greater than the moment it's executed.

 

NOW() -> datetime (2011-05-02 12:06:10)

SELECT col1, col2 FROM table WHERE date>=NOW()

 

CURDATE() -> date (2011-05-02)

SELECT col1, col2 FROM table WHERE date>=CURDATE()

Link to comment
Share on other sites

I do not have a database in place.

 

Let's say I have a text file with one date per line.

 

How would I fetch the lines of text (into an array, perhaps) and then display only the dates greater than moment executed?

Link to comment
Share on other sites

That would quite more complicated and really slow, but it's easily accomplished. However, without giving us a few event lines, we can't give a proper working solution.

 

PS: You should really opt for a database approach. It will be 100x easier to handle (inserts, updates, whatever).

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.