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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.