Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 238
  • Last Modified:

Don't display dates before today...

I have built a site with an events diary.

On the home page I display the next 4 events by selecting 4 recording from start_date ASC.

live
SELECT id, start_date, end_date, date_format(`start_date`,'%D %M %Y') as `formattedDate`, end_time, title, `description`, venue, link, icon, image, image_alignment, status FROM eventer_events ORDER BY start_date ASC

Open in new window


<span class="purpletext"><?php echo $row_latestnews['title']; ?></span><br>
          </h3>
          <span class="venuefeed"><?php echo $row_latestnews['venue']; ?></span><br>
          <?php echo $row_latestnews['formattedDate']; ?> </div>
      </div>
      <?php } while ($row_latestnews = mysql_fetch_assoc($latestnews)); ?>

Open in new window


The problem is that dates that have past will show at the top of the list. I need to not display an event that has already past, any ideas how to do this?

The date value is in the database as varchar(10) by the way...
0
BrighteyesDesign
Asked:
BrighteyesDesign
  • 2
1 Solution
 
Mark GilbertSenior Performance EngineerCommented:
May I recommend you look at an article I wrote about dates:

http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_3935-Working-with-Dates-and-Time-using-PHP-and-MySQL.html

Reason being is that there are some very powerful features available to you simply by setting your date field to a timestamp. It only takes up 4 bytes too.

The answer to your question is:

SELECT id, start_date, end_date, date_format(`start_date`,'%D %M %Y') as `formattedDate`, end_time, title, `description`, venue, link, icon, image, image_alignment, status FROM eventer_events where start_date > now() and end_date > now() ORDER BY start_date ASC

Open in new window


I put the clause on both the start and end dates just in case there was something funky going on with the end dates. If now() doesn't give you the value you need since you aren't using a timestamp you may have to preformat a variable with a date to filter by before constructing the sql. I do recommend against this though.
0
 
BrighteyesDesignAuthor Commented:
Great link, thanks, i'll use that next time.

I'm going to use the lazy option for now though!
0
 
Mark GilbertSenior Performance EngineerCommented:
Glad I was able to assist. Good luck with your project.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now