Solved

Don't display dates before today...

Posted on 2013-01-21
3
228 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
  • 2
3 Comments
 
LVL 18

Accepted Solution

by:
ingwa 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:ingwa
ID: 38801820
Glad I was able to assist. Good luck with your project.
0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

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

As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

910 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now