Solved

Don't display dates before today...

Posted on 2013-01-21
3
233 Views
Last Modified: 2013-01-21
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
Comment
Question by:BrighteyesDesign
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 18

Accepted Solution

by:
Mark Gilbert earned 500 total points
ID: 38801745
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
 

Author Comment

by:BrighteyesDesign
ID: 38801813
Great link, thanks, i'll use that next time.

I'm going to use the lazy option for now though!
0
 
LVL 18

Expert Comment

by:Mark Gilbert
ID: 38801820
Glad I was able to assist. Good luck with your project.
0

Featured Post

 Watch the Recording: Learning MySQL 5.7

MySQL 5.7 has a lot of new features. If you've dabbled with an older version of MySQL, it is definitely worth learning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

632 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question