Solved

Don't display dates before today...

Posted on 2013-01-21
3
229 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:
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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Doing something wrong with this PDO Select Statement... 3 18
Optimize the query 5 43
php56-php-mcrypt for rhel7 php56 1 47
MySQL - need to join three tables 2 46
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…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

840 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